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

App Dev Worksheet: Events

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

Answer key

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

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