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

App Dev Worksheet: Events

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

Answer key

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

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