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

App Dev Worksheet: Events

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

Answer key

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

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