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

App Dev Worksheet: Events

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

Answer key

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

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