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