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

App Dev Worksheet: Events

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

Answer key

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

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