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

App Dev Worksheet: Events

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

Answer key

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

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