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

App Dev Worksheet: Events

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

Answer key

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

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