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