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