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

App Dev Worksheet: Events

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

Answer key

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

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