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

App Dev Worksheet: Events

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

Answer key

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

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