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

App Dev Worksheet: Events

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

Answer key

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

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