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

App Dev Worksheet: Events

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

Answer key

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

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