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

App Dev Worksheet: Events

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

Answer key

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

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