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