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

App Dev Worksheet: Events

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

Answer key

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

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