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

App Dev Worksheet: Events

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

Answer key

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

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