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

App Dev Worksheet: Events

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

Answer key

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

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