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

App Dev Worksheet: Events

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

Answer key

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

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