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

App Dev Worksheet: Events

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

Answer key

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

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