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

App Dev Worksheet: Events

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

Answer key

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

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