App Dev Worksheet: Functions
Developer's tip (Write once, use often): function name(parameter) { …; return result; } — call it with name(value). Work out each call separately, then finish the line. Inside a function, if / return can give different results for different inputs.
NameDateTime takenScore ___ / 40
-
1.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 50;
}
show(fee(8) + fee(2)); -
2.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(38)); -
3.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 50;
}
show(fee(12) + fee(3)); -
4.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(55, 5)); -
5.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Kabir")); (a) greet (b) Well done, name! (c) Kabir (d) Well done, Kabir! -
6.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 50;
}
show(fee(3) + fee(5)); -
7.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(3)); -
8.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(65, 6)); -
9.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Meera")); (a) Well done, name! (b) Meera (c) greet (d) Well done, Meera! - 10.🧰 Why write a function? (a) to make code longer (b) to hide errors (c) to reuse code (d) to slow the app
-
11.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 3)); - 12.🧰 What does return do in a function? (a) deletes the app (b) sends back a value (c) repeats the code (d) closes the screen
-
13.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Meera")); (a) Hello, name! (b) Meera (c) Hello, Meera! (d) greet -
14.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(90, 4)); -
15.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(2)); -
16.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 40;
}
show(fee(1) + fee(4)); -
17.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(4)); -
18.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(31)); -
19.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(45, 5)); -
20.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 60;
}
show(fee(3) + fee(12)); -
21.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(3)); -
22.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(31)); -
23.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(0)); - 24.🧰 What is a function? (a) a named block of code (b) a list of colours (c) a type of phone (d) a screen size
-
25.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(23)); -
26.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Aman")); (a) Hi, name! (b) greet (c) Hi, Aman! (d) Aman -
27.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(35)); -
28.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(30, 2)); -
29.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 20;
}
show(fee(5) + fee(12)); -
30.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 20;
}
show(fee(11) + fee(6)); -
31.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Zoya")); (a) Well done, name! (b) Well done, Zoya! (c) greet (d) Zoya -
32.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Zoya")); (a) Welcome, name! (b) Zoya (c) greet (d) Welcome, Zoya! -
33.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(9)); - 34.🧰 In function tip(bill), what is bill? (a) a screen (b) an event (c) a parameter (d) a loop
-
35.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(1)); -
36.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(17)); -
37.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 40;
}
show(fee(10) + fee(2)); -
38.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Zoya")); (a) greet (b) Hi, Zoya! (c) Zoya (d) Hi, name! -
39.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Kabir")); (a) greet (b) Welcome, name! (c) Welcome, Kabir! (d) Kabir -
40.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(37));
Answer key
- 50
- 114
- 50
- 275
- Well done, Kabir!
- 50
- 60
- 390
- Well done, Meera!
- to reuse code
- 45
- sends back a value
- Hello, Meera!
- 360
- 80
- 0
- 100
- 62
- 225
- 60
- 80
- 93
- 60
- a named block of code
- 69
- Hi, Aman!
- 105
- 60
- 40
- 40
- Well done, Zoya!
- Welcome, Zoya!
- 18
- a parameter
- 60
- 51
- 40
- Hi, Zoya!
- Welcome, Kabir!
- 74
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students