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