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

App Dev Worksheet: Events

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

Answer key

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

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