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

App Dev Worksheet: Events

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

Answer key

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

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