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

App Dev Worksheet: Events

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

Answer key

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

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