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