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

App Dev Worksheet: Events

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

Answer key

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

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