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