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.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(36)); -
2.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(22)); - 3.🧰 In function tip(bill), what is bill? (a) a screen (b) a parameter (c) an event (d) a loop
-
4.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Meera")); (a) Welcome, Meera! (b) Welcome, name! (c) Meera (d) greet -
5.🧰 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(7) + fee(1)); -
6.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Zoya")); (a) Zoya (b) Hi, name! (c) Hi, Zoya! (d) greet - 7.🧰 What is a function? (a) a named block of code (b) a type of phone (c) a list of colours (d) a screen size
-
8.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(12)); -
9.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Kabir")); (a) Welcome, name! (b) Kabir (c) Welcome, Kabir! (d) greet -
10.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(5)); -
11.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(3)); -
12.🧰 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(1)); -
13.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(3)); -
14.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(1)); -
15.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(20, 5)); -
16.🧰 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(2) + fee(2)); -
17.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 5)); - 18.🧰 Why write a function? (a) to make code longer (b) to slow the app (c) to hide errors (d) to reuse code
-
19.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(85, 2)); -
20.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 2)); -
21.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(1)); -
22.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(5)); -
23.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(12)); -
24.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Aman")); (a) Well done, name! (b) greet (c) Well done, Aman! (d) Aman -
25.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(3)); -
26.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(27)); -
27.🧰 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(7) + fee(10)); -
28.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(70, 4)); -
29.🧰 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(6) + fee(9)); -
30.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(2)); -
31.🧰 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(11) + fee(12)); -
32.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Arjun")); (a) Hi, Arjun! (b) greet (c) Arjun (d) Hi, name! -
33.🧰 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(7) + fee(7)); -
34.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(90, 5)); -
35.🧰 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(12) + fee(2)); - 36.🧰 How do you run (call) a function called greet? (a) run greet (b) #greet (c) greet[] (d) greet()
-
37.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(55, 5)); -
38.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(7)); -
39.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Meera")); (a) Well done, name! (b) Well done, Meera! (c) greet (d) Meera -
40.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(65, 4));
Answer key
- 108
- 44
- a parameter
- Welcome, Meera!
- 30
- Hi, Zoya!
- a named block of code
- 36
- Welcome, Kabir!
- 100
- 50
- 0
- 80
- 70
- 100
- 0
- 75
- to reuse code
- 170
- 30
- 50
- 70
- 24
- Well done, Aman!
- 90
- 54
- 80
- 280
- 80
- 50
- 100
- Hi, Arjun!
- 60
- 450
- 40
- greet()
- 275
- 21
- Well done, Meera!
- 260
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students