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

App Dev Worksheet: Events

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

Answer key

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

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