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

App Dev Worksheet: Events

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

Answer key

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

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