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