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

App Dev Worksheet: Events

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

Answer key

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

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