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

App Dev Worksheet: Events

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

Answer key

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

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