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

App Dev Worksheet: Events

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

Answer key

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

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