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