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

App Dev Worksheet: Events

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

Answer key

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

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