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

App Dev Worksheet: Events

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

Answer key

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

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