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

App Dev Worksheet: Events

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

Answer key

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

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