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