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