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

App Dev Worksheet: Events

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

Answer key

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

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