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

App Dev Worksheet: Events

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

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