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