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