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

App Dev Worksheet: Events

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

Answer key

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

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