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

App Dev Worksheet: Events

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

Answer key

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

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