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

App Dev Worksheet: Events

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

Answer key

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

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