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