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

App Dev Worksheet: Events

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

Answer key

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

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