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

App Dev Worksheet: Events

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

Answer key

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

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