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

App Dev Worksheet: Events

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

Answer key

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

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