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

App Dev Worksheet: Events

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

Answer key

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

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