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

App Dev Worksheet: Events

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

Answer key

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

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