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

App Dev Worksheet: Events

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

Answer key

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

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