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

App Dev Worksheet: Events

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

Answer key

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

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