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

App Dev Worksheet: Events

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

Answer key

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

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