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

App Dev Worksheet: Events

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

Answer key

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

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