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

App Dev Worksheet: Events

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

Answer key

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

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