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