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

App Dev Worksheet: Events

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

Answer key

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

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