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

App Dev Worksheet: Events

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

Answer key

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

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