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