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

App Dev Worksheet: Events

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

Answer key

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

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