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

App Dev Worksheet: Events

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

Answer key

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

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