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

App Dev Worksheet: Events

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

Answer key

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

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