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

App Dev Worksheet: Events

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

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