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