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

App Dev Worksheet: Events

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

Answer key

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

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