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

App Dev Worksheet: Events

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

Answer key

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

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