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

App Dev Worksheet: Events

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

Answer key

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

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