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

App Dev Worksheet: Events

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

Answer key

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

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