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