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