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

App Dev Worksheet: Events

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

Answer key

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

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