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

App Dev Worksheet: Events

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

Answer key

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

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