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