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