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