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

App Dev Worksheet: Events

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

Answer key

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

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