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

App Dev Worksheet: Events

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

Answer key

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

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