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

App Dev Worksheet: Events

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

Answer key

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

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