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

App Dev Worksheet: Events

App development lesson 17: Events: on tap, do this · Set 159 · 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 taps the button 4 times. What number does the label show now?
    let lives = 5;
    button.onTap = function () {
      lives = lives + 2;
      label.text = lives;
    };
  2. 2.True or false: a countdown hits zero is a timer event. (a) True (b) False
  3. 3.👆 The user taps the button 4 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 3) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  4. 4.True or false: the user presses Save is a text event. (a) False (b) True
  5. 5.👆 The user taps the button 4 times. What number does the label show now?
    let points = 1;
    button.onTap = function () {
      points = points + 5;
      label.text = points;
    };
  6. 6.👆 The user taps the button 4 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 2) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  7. 7.👆 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;
    };
  8. 8.👆 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, Zoya! (b) Zoya (c) Hello! (d) Hello, nameBox.text!
  9. 9.True or false: the user presses Save is a load event. (a) True (b) False
  10. 10.👆 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
  11. 11.True or false: a finger hits Like is a tap event. (a) False (b) True
  12. 12.👆 The user taps the button 2 times. What number does the label show now?
    let score = 5;
    button.onTap = function () {
      score = score + 1;
      label.text = score;
    };
  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) OFF (b) ON
  14. 14.👆 The user taps the button 6 times. What number does the label show now?
    let points = 8;
    button.onTap = function () {
      points = points + 2;
      label.text = points;
    };
  15. 15.True or false: one second passes is a text event. (a) True (b) False
  16. 16.👆 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) Well done, nameBox.text! (d) Zoya
  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.👆 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;
    };
  19. 19.True or false: a countdown hits zero is a load event. (a) True (b) False
  20. 20.👆 The user taps the button 2 times. What number does the label show now?
    let stars = 3;
    button.onTap = function () {
      stars = stars + 1;
      label.text = stars;
    };
  21. 21.👆 A tap handler runs how many times if the user taps 4 times? (a) 1 (b) 4 (c) 8 (d) 0
  22. 22.👆 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
  23. 23.👆 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
  24. 24.👆 The user types Zoya in nameBox and taps the button 1 time. What does the label show?
    button.onTap = function () {
      label.text = "Welcome, " + nameBox.text + "!";
    };
    (a) Welcome! (b) Zoya (c) Welcome, Zoya! (d) Welcome, nameBox.text!
  25. 25.👆 The user taps the button 2 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 4) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  26. 26.👆 Which of these is an event? (a) the user taps a button (b) the icon colour (c) a list of names (d) the font size
  27. 27.👆 The user taps the button 5 times. What number does the label show now?
    let score = 10;
    button.onTap = function () {
      score = score + 3;
      label.text = score;
    };
  28. 28.👆 The user taps the button 4 times. What number does the label show now?
    let points = 10;
    button.onTap = function () {
      points = points + 4;
      label.text = points;
    };
  29. 29.👆 What kind of event is this: a 5-minute alarm ends? (a) a text event (b) a timer event (c) a tap event (d) a load event
  30. 30.👆 The user taps the button 3 times. What number does the label show now?
    let points = 4;
    button.onTap = function () {
      points = points + 2;
      label.text = points;
    };
  31. 31.👆 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;
    };
  32. 32.👆 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! (c) Aman (d) Hello, nameBox.text!
  33. 33.👆 What kind of event is this: the user taps Play? (a) a timer event (b) a text event (c) a tap event (d) a load event
  34. 34.True or false: the screen first opens is a load event. (a) False (b) True
  35. 35.👆 The user taps the button 6 times. What number does the label show now?
    let coins = 4;
    button.onTap = function () {
      coins = coins + 4;
      label.text = coins;
    };
  36. 36.👆 The user taps the button 1 times. What number does the label show now?
    let likes = 0;
    button.onTap = function () {
      if (likes < 4) {
        likes = likes + 1;
      }
      label.text = likes;
    };
  37. 37.👆 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;
    };
  38. 38.👆 What kind of event is this: the user presses Save? (a) a timer event (b) a tap event (c) a text event (d) a load event
  39. 39.👆 The user taps the button 3 times. What number does the label show now?
    let score = 4;
    button.onTap = function () {
      score = score + 2;
      label.text = score;
    };
  40. 40.👆 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;
    };

Answer key

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

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