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

App Dev Worksheet: Events

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

Answer key

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

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