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

App Dev Worksheet: Events

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

Answer key

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

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