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