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

App Dev Worksheet: Events

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

Answer key

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

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