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