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

App Dev Worksheet: Events

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

Answer key

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

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