← Events: on tap, do this lesson New set →

App Dev Worksheet: Events

App development lesson 17: Events: on tap, do this · Set 302 · 40 questions
TalentJR

Developer's tip (When this, do that): Event → handler → action: “on tap, do this”. The handler runs once for every tap. Counter: start + taps × step. A limit stops it growing; on = !on flips ON / OFF.

NameDateTime takenScore ___ / 40
  1. 1.👆 The user taps the button 4 times. What number does the label show now?
    let score = 2;
    button.onTap = function () {
      score = score + 5;
      label.text = score;
    };
  2. 2.👆 The user taps the button 3 times. What number does the label show now?
    let coins = 8;
    button.onTap = function () {
      coins = coins + 3;
      label.text = coins;
    };
  3. 3.👆 The user taps the button 3 times. What number does the label show now?
    let points = 2;
    button.onTap = function () {
      points = points + 2;
      label.text = points;
    };
  4. 4.👆 The user types Arjun in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Welcome, " + nameBox.text + "!";
    };
    (a) Welcome, nameBox.text! (b) Arjun (c) Welcome, Arjun! (d) Welcome!
  5. 5.👆 Which of these is an event? (a) the icon colour (b) the font size (c) a list of names (d) the user taps a button
  6. 6.👆 The user types Kabir in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Well done, " + nameBox.text + "!";
    };
    (a) Well done, Kabir! (b) Kabir (c) Well done, nameBox.text! (d) Well done!
  7. 7.👆 “On tap → do this” links an event to ___. (a) a charger (b) an action (c) a web address (d) a font
  8. 8.👆 The user taps the button 2 times. What does the label show now?
    let on = false;
    button.onTap = function () {
      on = !on;
      if (on) {
        label.text = "ON";
      } else {
        label.text = "OFF";
      }
    };
    (a) ON (b) OFF
  9. 9.👆 The user taps the button 3 times. What number does the label show now?
    let stars = 3;
    button.onTap = function () {
      stars = stars + 1;
      label.text = stars;
    };
  10. 10.True or false: a 5-minute alarm ends is a tap event. (a) True (b) False
  11. 11.👆 A tap handler runs how many times if the user taps 4 times? (a) 4 (b) 0 (c) 8 (d) 1
  12. 12.👆 The user types Arjun in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Hello, " + nameBox.text + "!";
    };
    (a) Hello! (b) Arjun (c) Hello, Arjun! (d) Hello, nameBox.text!
  13. 13.👆 The user taps the button 6 times. What does the label show now?
    let on = false;
    button.onTap = function () {
      on = !on;
      if (on) {
        label.text = "ON";
      } else {
        label.text = "OFF";
      }
    };
    (a) OFF (b) ON
  14. 14.True or false: the app starts up is a load event. (a) False (b) True
  15. 15.True or false: the user presses Save is a tap event. (a) False (b) True
  16. 16.👆 What kind of event is this: the user presses Save? (a) a text event (b) a load event (c) a timer event (d) a tap event
  17. 17.👆 The user taps the button 2 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 5) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  18. 18.👆 The user types Riya in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Hello, " + nameBox.text + "!";
    };
    (a) Riya (b) Hello, nameBox.text! (c) Hello, Riya! (d) Hello!
  19. 19.👆 The user taps the button 2 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 2) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  20. 20.👆 What kind of event is this: one second passes? (a) a tap event (b) a load event (c) a timer event (d) a text event
  21. 21.👆 The user types Riya in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Well done, " + nameBox.text + "!";
    };
    (a) Well done, Riya! (b) Well done! (c) Well done, nameBox.text! (d) Riya
  22. 22.True or false: one second passes is a timer event. (a) False (b) True
  23. 23.👆 The user taps the button 7 times. What does the label show now?
    let on = false;
    button.onTap = function () {
      on = !on;
      if (on) {
        label.text = "ON";
      } else {
        label.text = "OFF";
      }
    };
    (a) OFF (b) ON
  24. 24.👆 The user types Aman in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Well done, " + nameBox.text + "!";
    };
    (a) Well done! (b) Aman (c) Well done, nameBox.text! (d) Well done, Aman!
  25. 25.👆 The user taps the button 5 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 3) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  26. 26.👆 The user taps the button 8 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 3) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  27. 27.👆 The user taps the button 3 times. What number does the label show now?
    let points = 3;
    button.onTap = function () {
      points = points + 3;
      label.text = points;
    };
  28. 28.True or false: the user types a letter is a load event. (a) True (b) False
  29. 29.👆 What kind of event is this: a finger hits Like? (a) a timer event (b) a load event (c) a tap event (d) a text event
  30. 30.👆 The user taps the button 4 times. What does the label show now?
    let on = false;
    button.onTap = function () {
      on = !on;
      if (on) {
        label.text = "ON";
      } else {
        label.text = "OFF";
      }
    };
    (a) ON (b) OFF
  31. 31.👆 An event in an app is ___. (a) something that happens (b) a kind of list (c) a colour theme (d) an app store
  32. 32.👆 Code that runs when an event happens is called a ___. (a) hashtag (b) header (c) handler (d) headline
  33. 33.👆 The user types Kabir in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Hello, " + nameBox.text + "!";
    };
    (a) Hello, Kabir! (b) Kabir (c) Hello, nameBox.text! (d) Hello!
  34. 34.👆 The user types Zoya in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Welcome, " + nameBox.text + "!";
    };
    (a) Welcome, nameBox.text! (b) Welcome! (c) Zoya (d) Welcome, Zoya!
  35. 35.👆 The user types Aman in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Hello, " + nameBox.text + "!";
    };
    (a) Hello, Aman! (b) Hello! (c) Hello, nameBox.text! (d) Aman
  36. 36.👆 The user taps the button 3 times. What number does the label show now?
    let coins = 10;
    button.onTap = function () {
      coins = coins + 3;
      label.text = coins;
    };
  37. 37.👆 The user taps the button 3 times. What number does the label show now?
    let coins = 1;
    button.onTap = function () {
      coins = coins + 1;
      label.text = coins;
    };
  38. 38.👆 The user taps the button 3 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 3) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  39. 39.👆 What kind of event is this: a countdown hits zero? (a) a tap event (b) a load event (c) a timer event (d) a text event
  40. 40.👆 What kind of event is this: the app starts up? (a) a text event (b) a timer event (c) a tap event (d) a load event

Answer key

  1. 22
  2. 17
  3. 8
  4. Welcome, Arjun!
  5. the user taps a button
  6. Well done, Kabir!
  7. an action
  8. OFF
  9. 6
  10. False
  11. 4
  12. Hello, Arjun!
  13. OFF
  14. True
  15. True
  16. a tap event
  17. 2
  18. Hello, Riya!
  19. 2
  20. a timer event
  21. Well done, Riya!
  22. True
  23. ON
  24. Well done, Aman!
  25. 3
  26. 3
  27. 12
  28. False
  29. a tap event
  30. OFF
  31. something that happens
  32. handler
  33. Hello, Kabir!
  34. Welcome, Zoya!
  35. Hello, Aman!
  36. 19
  37. 4
  38. 3
  39. a timer event
  40. a load event

Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students