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