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