App Dev Worksheet: Events
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.👆 The user taps the button 5 times. What number does the label show now?
let score = 1;
button.onTap = function () {
score = score + 5;
label.text = score;
}; - 2.👆 What kind of event is this: a countdown hits zero? (a) a tap event (b) a load event (c) a text event (d) a timer event
-
3.👆 The user taps the button 3 times. What number does the label show now?
let stars = 4;
button.onTap = function () {
stars = stars + 1;
label.text = stars;
}; - 4.True or false: a finger hits Like is a timer event. (a) True (b) False
-
5.👆 The user taps the button 3 times. What number does the label show now?
let stars = 9;
button.onTap = function () {
stars = stars + 1;
label.text = stars;
}; -
6.👆 The user taps the button 3 times. What number does the label show now?
let score = 6;
button.onTap = function () {
score = score + 5;
label.text = score;
}; -
7.👆 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;
}; -
8.👆 The user taps the button 2 times. What number does the label show now?
let stars = 1;
button.onTap = function () {
stars = stars + 5;
label.text = stars;
}; - 9.👆 An event in an app is ___. (a) a kind of list (b) a colour theme (c) an app store (d) something that happens
-
10.👆 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) Hello! (b) Hello, nameBox.text! (c) Arjun (d) Hello, Arjun! - 11.👆 What kind of event is this: a finger hits Like? (a) a load event (b) a tap event (c) a timer event (d) a text event
-
12.👆 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, nameBox.text! (c) Well done, Arjun! (d) Well done! -
13.👆 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;
}; -
14.👆 The user taps the button 5 times. What number does the label show now?
let coins = 9;
button.onTap = function () {
coins = coins + 3;
label.text = coins;
}; - 15.👆 Code that runs when an event happens is called a ___. (a) hashtag (b) header (c) headline (d) handler
-
16.👆 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;
}; - 17.👆 What kind of event is this: the screen first opens? (a) a text event (b) a load event (c) a tap event (d) a timer event
- 18.👆 What kind of event is this: the search box changes? (a) a timer event (b) a load event (c) a tap event (d) a text event
- 19.True or false: the user presses Save is a load event. (a) False (b) True
- 20.True or false: the screen first opens is a timer event. (a) False (b) True
-
21.👆 The user taps the button 2 times. What number does the label show now?
let stars = 9;
button.onTap = function () {
stars = stars + 2;
label.text = stars;
}; - 22.👆 What kind of event is this: the user presses Save? (a) a text event (b) a load event (c) a tap event (d) a timer event
-
23.👆 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 - 24.👆 What kind of event is this: the user taps Play? (a) a text event (b) a tap event (c) a load event (d) a timer event
-
25.👆 The user taps the button 6 times. What number does the label show now?
let likes = 0;
button.onTap = function () {
if (likes < 3) {
likes = likes + 1;
}
label.text = likes;
}; - 26.👆 What kind of event is this: one second passes? (a) a timer event (b) a load event (c) a tap event (d) a text event
-
27.👆 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 -
28.👆 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 -
29.👆 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 -
30.👆 The user taps the button 5 times. What number does the label show now?
let lives = 5;
button.onTap = function () {
lives = lives + 2;
label.text = lives;
}; -
31.👆 The user taps the button 3 times. What number does the label show now?
let coins = 3;
button.onTap = function () {
coins = coins + 4;
label.text = coins;
}; -
32.👆 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;
}; -
33.👆 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;
}; - 34.True or false: a 5-minute alarm ends is a timer event. (a) False (b) True
-
35.👆 The user taps the button 8 times. What number does the label show now?
let likes = 0;
button.onTap = function () {
if (likes < 3) {
likes = likes + 1;
}
label.text = likes;
}; -
36.👆 The user taps the button 3 times. What number does the label show now?
let coins = 2;
button.onTap = function () {
coins = coins + 4;
label.text = coins;
}; -
37.👆 The user taps the button 2 times. What number does the label show now?
let score = 10;
button.onTap = function () {
score = score + 1;
label.text = score;
}; -
38.👆 The user taps the button 3 times. What number does the label show now?
let score = 0;
button.onTap = function () {
score = score + 2;
label.text = score;
}; -
39.👆 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;
}; -
40.👆 The user taps the button 4 times. What number does the label show now?
let stars = 2;
button.onTap = function () {
stars = stars + 4;
label.text = stars;
};
Answer key
- 26
- a timer event
- 7
- False
- 12
- 21
- 3
- 11
- something that happens
- Hello, Arjun!
- a tap event
- Well done, Arjun!
- 1
- 24
- handler
- 4
- a load event
- a text event
- False
- False
- 13
- a tap event
- OFF
- a tap event
- 3
- a timer event
- OFF
- ON
- Hi, Riya!
- 15
- 15
- 3
- 2
- True
- 3
- 14
- 12
- 6
- 5
- 18
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students