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

App Dev Worksheet: Events

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

Answer key

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

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