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

App Dev Worksheet: Events

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

Answer key

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

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