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

App Dev Worksheet: Events

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

Answer key

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

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