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

App Dev Worksheet: Events

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

Answer key

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

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