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

App Dev Worksheet: Events

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

Answer key

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

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