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

App Dev Worksheet: Events

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

Answer key

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

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