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

App Dev Worksheet: Events

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

Answer key

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

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