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

App Dev Worksheet: Events

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

Answer key

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

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