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

App Dev Worksheet: Events

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

Answer key

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

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