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

App Dev Worksheet: Events

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

Answer key

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

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