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

App Dev Worksheet: Events

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

Answer key

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

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