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

App Dev Worksheet: Events

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

Answer key

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

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