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

App Dev Worksheet: Events

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

Answer key

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

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