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

App Dev Worksheet: Events

App development lesson 17: Events: on tap, do this · Set 125 · 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.True or false: a 5-minute alarm ends is a text event. (a) True (b) False
  2. 2.👆 The user taps the button 4 times. What number does the label show now?
    let coins = 1;
    button.onTap = function () {
      coins = coins + 1;
      label.text = coins;
    };
  3. 3.👆 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
  4. 4.👆 What kind of event is this: the screen first opens? (a) a load event (b) a tap event (c) a timer event (d) a text event
  5. 5.👆 The user taps the button 2 times. What number does the label show now?
    let lives = 2;
    button.onTap = function () {
      lives = lives + 1;
      label.text = lives;
    };
  6. 6.👆 The user taps the button 7 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 2) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  7. 7.True or false: the search box changes is a tap event. (a) True (b) False
  8. 8.👆 The user taps the button 4 times. What number does the label show now?
    let lives = 4;
    button.onTap = function () {
      lives = lives + 4;
      label.text = lives;
    };
  9. 9.👆 The user types Kabir 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) Welcome, Kabir! (d) Kabir
  10. 10.👆 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) ON (b) OFF
  11. 11.👆 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) OFF (b) ON
  12. 12.True or false: the user types a letter is a tap event. (a) False (b) True
  13. 13.👆 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! (b) Well done, Riya! (c) Well done, nameBox.text! (d) Riya
  14. 14.True or false: a 5-minute alarm ends is a tap event. (a) False (b) True
  15. 15.👆 The user taps the button 2 times. What number does the label show now?
    let lives = 10;
    button.onTap = function () {
      lives = lives + 4;
      label.text = lives;
    };
  16. 16.👆 The user taps the button 1 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
  17. 17.👆 The user taps the button 3 times. What number does the label show now?
    let stars = 5;
    button.onTap = function () {
      stars = stars + 4;
      label.text = stars;
    };
  18. 18.👆 Code that runs when an event happens is called a ___. (a) hashtag (b) headline (c) handler (d) header
  19. 19.👆 What kind of event is this: the app starts up? (a) a tap event (b) a timer event (c) a text event (d) a load event
  20. 20.👆 What kind of event is this: the search box changes? (a) a load event (b) a tap event (c) a timer event (d) a text event
  21. 21.True or false: the screen first opens is a text event. (a) False (b) True
  22. 22.👆 An event in an app is ___. (a) a kind of list (b) something that happens (c) a colour theme (d) an app store
  23. 23.👆 The user types Kabir in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Hi, " + nameBox.text + "!";
    };
    (a) Hi, Kabir! (b) Kabir (c) Hi! (d) Hi, nameBox.text!
  24. 24.👆 What kind of event is this: a finger hits Like? (a) a text event (b) a load event (c) a timer event (d) a tap event
  25. 25.👆 The user taps the button 6 times. What number does the label show now?
    let points = 3;
    button.onTap = function () {
      points = points + 1;
      label.text = points;
    };
  26. 26.👆 The user taps the button 7 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 4) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  27. 27.👆 “On tap → do this” links an event to ___. (a) a web address (b) a charger (c) an action (d) a font
  28. 28.👆 Which of these is an event? (a) the icon colour (b) a list of names (c) the font size (d) the user taps a button
  29. 29.True or false: the user taps Play is a timer event. (a) False (b) True
  30. 30.👆 The user taps the button 3 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.True or false: the user taps Play is a tap event. (a) False (b) True
  32. 32.👆 The user taps the button 6 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 3) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  33. 33.True or false: one second passes is a timer event. (a) False (b) True
  34. 34.True or false: the screen first opens is a load event. (a) True (b) False
  35. 35.👆 The user types Meera in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Hi, " + nameBox.text + "!";
    };
    (a) Hi, Meera! (b) Hi, nameBox.text! (c) Meera (d) Hi!
  36. 36.👆 The user taps the button 7 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 3) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  37. 37.👆 What kind of event is this: a 5-minute alarm ends? (a) a load event (b) a tap event (c) a timer event (d) a text event
  38. 38.👆 The user taps the button 5 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
  39. 39.True or false: a finger hits Like is a tap event. (a) False (b) True
  40. 40.👆 The user taps the button 3 times. What number does the label show now?
    let lives = 9;
    button.onTap = function () {
      lives = lives + 1;
      label.text = lives;
    };

Answer key

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

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