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

App Dev Worksheet: Events

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

Answer key

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

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