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

App Dev Worksheet: Events

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

Answer key

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

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