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

App Dev Worksheet: Events

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

Answer key

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

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