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

App Dev Worksheet: Events

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

Answer key

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

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