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