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

App Dev Worksheet: Events

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

Answer key

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

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