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