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

App Dev Worksheet: Events

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

Answer key

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

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