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

App Dev Worksheet: Events

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

Answer key

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

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