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

App Dev Worksheet: Events

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

Answer key

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

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