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

App Dev Worksheet: Events

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

Answer key

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

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