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

App Dev Worksheet: Events

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

Answer key

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

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