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

App Dev Worksheet: Events

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

Answer key

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

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