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

App Dev Worksheet: Events

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

Answer key

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

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