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.🧰 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(1) + fee(4)); - 2.🧰 What does return do in a function? (a) sends back a value (b) deletes the app (c) repeats the code (d) closes the screen
-
3.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(5)); - 4.🧰 What is a function? (a) a screen size (b) a type of phone (c) a list of colours (d) a named block of code
-
5.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(5)); -
6.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(65, 4)); -
7.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(0)); -
8.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Meera")); (a) Hello, Meera! (b) Hello, name! (c) greet (d) Meera -
9.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(4)); -
10.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(29)); -
11.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(75, 4)); -
12.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(2)); -
13.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(25, 5)); -
14.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(3)); - 15.🧰 In function tip(bill), what is bill? (a) a parameter (b) a loop (c) a screen (d) an event
-
16.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(4)); -
17.🧰 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(4) + fee(5)); -
18.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Riya")); (a) Well done, name! (b) greet (c) Riya (d) Well done, Riya! -
19.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Zoya")); (a) Hello, Zoya! (b) Hello, name! (c) greet (d) Zoya -
20.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 2)); -
21.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(4)); -
22.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(12)); -
23.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(40)); -
24.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(70, 2)); -
25.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(4)); -
26.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(21)); -
27.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(27)); - 28.🧰 How do you run (call) a function called greet? (a) run greet (b) #greet (c) greet[] (d) greet()
-
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(6) + fee(10)); -
30.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(4)); -
31.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Arjun")); (a) Arjun (b) Well done, Arjun! (c) Well done, name! (d) greet -
32.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(40)); -
33.🧰 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(4)); -
34.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(3)); -
35.🧰 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(3)); -
36.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(15)); -
37.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(100, 4)); -
38.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(60, 6)); -
39.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(10, 4)); -
40.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(5));
Answer key
- 0
- sends back a value
- 15
- a named block of code
- 80
- 260
- 40
- Hello, Meera!
- 8
- 58
- 300
- 70
- 125
- 80
- a parameter
- 100
- 30
- Well done, Riya!
- Hello, Zoya!
- 30
- 12
- 36
- 80
- 140
- 90
- 63
- 54
- greet()
- 80
- 60
- Well done, Arjun!
- 120
- 20
- 60
- 40
- 30
- 400
- 360
- 40
- 100
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students