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

App Dev Worksheet: Events

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

Answer key

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

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