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