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

App Dev Worksheet: Events

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

Answer key

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

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