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