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