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