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

App Dev Worksheet: Events

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

Answer key

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

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