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

App Dev Worksheet: Events

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

Answer key

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

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