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