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

App Dev Worksheet: Events

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

Answer key

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

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