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

App Dev Worksheet: Events

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

Answer key

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

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