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