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

App Dev Worksheet: Events

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

Answer key

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

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