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

App Dev Worksheet: Events

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

Answer key

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

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