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