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

App Dev Worksheet: Events

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

Answer key

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

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