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

App Dev Worksheet: Events

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

Answer key

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

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