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

App Dev Worksheet: Events

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

Answer key

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

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