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

App Dev Worksheet: Events

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

Answer key

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

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