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

App Dev Worksheet: Events

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

Answer key

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

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