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

App Dev Worksheet: Events

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

Answer key

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

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