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