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

App Dev Worksheet: Events

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

Answer key

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

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