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

App Dev Worksheet: Events

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

Answer key

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

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