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

App Dev Worksheet: Events

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

Answer key

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

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