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

App Dev Worksheet: Events

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

Answer key

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

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