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