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

App Dev Worksheet: Events

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

Answer key

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

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