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

App Dev Worksheet: Events

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

Answer key

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

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