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 double(n) {
return n * 2;
}
show(double(36)); - 2.🧰 In function tip(bill), what is bill? (a) an event (b) a parameter (c) a loop (d) a screen
- 3.🧰 What does return do in a function? (a) deletes the app (b) repeats the code (c) closes the screen (d) sends back a value
-
4.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 3)); -
5.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 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 60;
}
show(fee(3) + fee(7)); -
7.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(4)); - 8.🧰 What is a function? (a) a named block of code (b) a screen size (c) a list of colours (d) a type of phone
-
9.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(55, 5)); -
10.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(18)); -
11.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(11)); -
12.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(80, 3)); -
13.🧰 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(8) + fee(4)); -
14.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(60, 4)); -
15.🧰 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(6) + fee(1)); -
16.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(0)); -
17.🧰 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(7)); -
18.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(1)); -
19.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(40, 4)); -
20.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(26)); -
21.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Aman")); (a) Hi, name! (b) Hi, Aman! (c) Aman (d) greet -
22.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Zoya")); (a) greet (b) Hi, name! (c) Zoya (d) Hi, Zoya! -
23.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(90, 4)); -
24.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(40)); -
25.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(85, 4)); -
26.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Arjun")); (a) greet (b) Well done, Arjun! (c) Arjun (d) Well done, name! -
27.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(39)); -
28.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Zoya")); (a) greet (b) Zoya (c) Welcome, Zoya! (d) Welcome, name! -
29.🧰 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(4)); -
30.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Aman")); (a) Hello, Aman! (b) greet (c) Hello, name! (d) Aman -
31.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(0)); -
32.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(30, 5)); -
33.🧰 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(10)); -
34.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(80, 6)); -
35.🧰 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(1)); -
36.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(32)); -
37.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(3)); -
38.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(50, 2)); -
39.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Riya")); (a) greet (b) Well done, Riya! (c) Well done, name! (d) Riya -
40.🧰 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(12) + fee(9));
Answer key
- 72
- a parameter
- sends back a value
- 105
- 60
- 60
- 80
- a named block of code
- 275
- 36
- 22
- 240
- 50
- 240
- 50
- 20
- 120
- 70
- 160
- 52
- Hi, Aman!
- Hi, Zoya!
- 360
- 120
- 340
- Well done, Arjun!
- 78
- Welcome, Zoya!
- 40
- Hello, Aman!
- 60
- 150
- 120
- 480
- 50
- 64
- 70
- 100
- Well done, Riya!
- 60
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students