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

App Dev Worksheet: Events

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

Answer key

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

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