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

App Dev Worksheet: Events

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

Answer key

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

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