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

App Dev Worksheet: Events

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

Answer key

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

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