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