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

App Dev Worksheet: Events

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

Answer key

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

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