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(3)); -
2.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(6)); -
3.🧰 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(8) + fee(6)); -
4.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(2)); -
5.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(1)); -
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(10) + fee(5)); -
7.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Meera")); (a) Well done, name! (b) Meera (c) greet (d) Well done, Meera! -
8.🧰 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(10)); -
9.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(0)); -
10.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Aman")); (a) Aman (b) Hi, name! (c) greet (d) Hi, Aman! -
11.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(10, 6)); -
12.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(1)); -
13.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(70, 6)); -
14.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(3)); -
15.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(24)); -
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(9)); -
17.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Aman")); (a) Aman (b) greet (c) Well done, name! (d) Well done, Aman! - 18.🧰 What is a function? (a) a list of colours (b) a screen size (c) a named block of code (d) a type of phone
-
19.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(34)); -
20.🧰 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(9)); -
21.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(80, 5)); -
22.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Zoya")); (a) Welcome, name! (b) Zoya (c) greet (d) Welcome, Zoya! -
23.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(5)); -
24.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(32)); - 25.🧰 What does return do in a function? (a) closes the screen (b) repeats the code (c) sends back a value (d) deletes the app
-
26.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Riya")); (a) Riya (b) greet (c) Hi, name! (d) Hi, Riya! -
27.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Kabir")); (a) greet (b) Hi, name! (c) Hi, Kabir! (d) Kabir -
28.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(22)); - 29.🧰 In function tip(bill), what is bill? (a) a loop (b) a parameter (c) an event (d) a screen
-
30.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(30, 4)); -
31.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Meera")); (a) greet (b) Hi, Meera! (c) Hi, name! (d) Meera -
32.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 3)); -
33.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(25, 3)); -
34.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(2)); -
35.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(6)); -
36.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(37)); - 37.🧰 Why write a function? (a) to make code longer (b) to hide errors (c) to slow the app (d) to reuse code
-
38.🧰 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(9) + fee(4)); -
39.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(30)); -
40.🧰 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(12));
Answer key
- 50
- 12
- 80
- 50
- 50
- 60
- Well done, Meera!
- 50
- 20
- Hi, Aman!
- 60
- 30
- 420
- 60
- 48
- 80
- Well done, Aman!
- a named block of code
- 68
- 50
- 400
- Welcome, Zoya!
- 70
- 64
- sends back a value
- Hi, Riya!
- Hi, Kabir!
- 66
- a parameter
- 120
- Hi, Meera!
- 45
- 75
- 40
- 18
- 74
- to reuse code
- 20
- 90
- 40
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students