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