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

App Dev Worksheet: Events

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

Answer key

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

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