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

App Dev Worksheet: Events

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

Answer key

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

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