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

App Dev Worksheet: Events

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

Answer key

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

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