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

App Dev Worksheet: Events

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

Answer key

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

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