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

App Dev Worksheet: Events

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

Answer key

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

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