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

App Dev Worksheet: Events

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

Answer key

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

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