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

App Dev Worksheet: Events

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

Answer key

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

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