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

App Dev Worksheet: Events

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

Answer key

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

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