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