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

App Dev Worksheet: Events

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

Answer key

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

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