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

App Dev Worksheet: Events

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

Answer key

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

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