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

App Dev Worksheet: Events

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

Answer key

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

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