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

App Dev Worksheet: Events

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

Answer key

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

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