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