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