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

App Dev Worksheet: Events

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

Answer key

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

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