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

App Dev Worksheet: Events

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

Answer key

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

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