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

App Dev Worksheet: Events

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

Answer key

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

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