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

App Dev Worksheet: Events

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

Answer key

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

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