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

App Dev Worksheet: Events

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

Answer key

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

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