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

App Dev Worksheet: Events

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

Answer key

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

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