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

App Dev Worksheet: Events

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

Answer key

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

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