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

App Dev Worksheet: Events

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

Answer key

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

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