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