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 60;
}
show(fee(1) + fee(10)); - 2.🧰 What does return do in a function? (a) closes the screen (b) repeats the code (c) deletes the app (d) sends back a value
-
3.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 30;
}
show(fee(5) + fee(7)); -
4.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(0)); -
5.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(0)); -
6.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(19)); - 7.🧰 In function tip(bill), what is bill? (a) a parameter (b) an event (c) a screen (d) a loop
-
8.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Meera")); (a) Well done, name! (b) greet (c) Meera (d) Well done, Meera! -
9.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(0)); -
10.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Riya")); (a) Hi, name! (b) greet (c) Hi, Riya! (d) Riya -
11.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Arjun")); (a) Well done, name! (b) Arjun (c) greet (d) Well done, Arjun! -
12.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(18)); -
13.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(25, 5)); -
14.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(30, 6)); -
15.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(3)); -
16.🧰 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(2) + fee(6)); -
17.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Aman")); (a) greet (b) Welcome, Aman! (c) Welcome, name! (d) Aman -
18.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(25)); -
19.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(1)); -
20.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Zoya")); (a) Zoya (b) greet (c) Hello, name! (d) Hello, Zoya! - 21.🧰 Why write a function? (a) to slow the app (b) to reuse code (c) to hide errors (d) to make code longer
-
22.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 30;
}
show(fee(12) + fee(5)); -
23.🧰 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(4) + fee(6)); -
24.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(16)); -
25.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(5)); - 26.🧰 What is a function? (a) a screen size (b) a type of phone (c) a named block of code (d) a list of colours
-
27.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Zoya")); (a) greet (b) Welcome, Zoya! (c) Welcome, name! (d) Zoya -
28.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Riya")); (a) Welcome, name! (b) Welcome, Riya! (c) Riya (d) greet -
29.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 30;
}
show(fee(10) + 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 50;
}
show(fee(9) + fee(9)); -
31.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Kabir")); (a) Welcome, name! (b) Welcome, Kabir! (c) greet (d) Kabir -
32.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(33)); -
33.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Arjun")); (a) greet (b) Hi, name! (c) Arjun (d) Hi, Arjun! -
34.🧰 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(4) + fee(11)); -
35.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(90, 4)); -
36.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(65, 3)); -
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(4) + fee(5)); -
38.🧰 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(7)); -
39.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(5)); -
40.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(4));
Answer key
- 60
- sends back a value
- 60
- 20
- 40
- 38
- a parameter
- Well done, Meera!
- 60
- Hi, Riya!
- Well done, Arjun!
- 36
- 125
- 180
- 90
- 60
- Welcome, Aman!
- 75
- 30
- Hello, Zoya!
- to reuse code
- 60
- 60
- 48
- 80
- a named block of code
- Welcome, Zoya!
- Welcome, Riya!
- 60
- 100
- Welcome, Kabir!
- 66
- Hi, Arjun!
- 60
- 360
- 195
- 40
- 50
- 70
- 60
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students