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

App Dev Worksheet: Events

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

Answer key

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

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