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