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

App Dev Worksheet: Events

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

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