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

App Dev Worksheet: Events

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

Answer key

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

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