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

App Dev Worksheet: Events

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

Answer key

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

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