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

App Dev Worksheet: Events

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

Answer key

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

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