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

App Dev Worksheet: Events

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

Answer key

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

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