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 total(price, qty) {
return price * qty;
}
show(total(25, 3)); -
2.🧰 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(9)); -
3.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(2)); -
4.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(70, 2)); -
5.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(1)); -
6.🧰 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(4)); -
7.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(70, 6)); -
8.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Kabir")); (a) Well done, name! (b) greet (c) Kabir (d) Well done, Kabir! -
9.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(12)); - 10.🧰 What does return do in a function? (a) sends back a value (b) repeats the code (c) closes the screen (d) deletes the app
-
11.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Aman")); (a) Hello, name! (b) Aman (c) Hello, Aman! (d) greet -
12.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(1)); -
13.🧰 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(1)); -
14.🧰 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(10)); -
15.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(10)); - 16.🧰 In function tip(bill), what is bill? (a) a loop (b) an event (c) a parameter (d) a screen
-
17.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(4)); -
18.🧰 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(2) + fee(11)); -
19.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Riya")); (a) greet (b) Hi, name! (c) Hi, Riya! (d) Riya -
20.🧰 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(11) + fee(3)); - 21.🧰 What is a function? (a) a screen size (b) a list of colours (c) a type of phone (d) a named block of code
-
22.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(36)); -
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(6) + fee(1)); -
24.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(4)); -
25.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(20, 6)); -
26.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Arjun")); (a) Arjun (b) Hello, Arjun! (c) greet (d) Hello, name! -
27.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 6)); -
28.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Zoya")); (a) Zoya (b) Hello, name! (c) Hello, Zoya! (d) greet -
29.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(0)); -
30.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(22)); -
31.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(50, 3)); - 32.🧰 How do you run (call) a function called greet? (a) greet() (b) #greet (c) greet[] (d) run greet
-
33.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Aman")); (a) Well done, name! (b) Aman (c) Well done, Aman! (d) greet -
34.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(4)); -
35.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 3)); -
36.🧰 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(4) + fee(11)); -
37.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(75, 4)); -
38.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(2)); -
39.🧰 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(3)); -
40.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(85, 3));
Answer key
- 75
- 100
- 60
- 140
- 30
- 40
- 420
- Well done, Kabir!
- 36
- sends back a value
- Hello, Aman!
- 40
- 0
- 50
- 30
- a parameter
- 80
- 50
- Hi, Riya!
- 30
- a named block of code
- 72
- 60
- 60
- 120
- Hello, Arjun!
- 210
- Hello, Zoya!
- 50
- 44
- 150
- greet()
- Well done, Aman!
- 70
- 45
- 20
- 300
- 80
- 50
- 255
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students