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

App Dev Worksheet: Events

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

Answer key

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

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