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

App Dev Worksheet: Events

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

Answer key

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

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