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

App Dev Worksheet: Events

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

Answer key

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

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