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