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

App Dev Worksheet: Events

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

Answer key

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

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