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