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