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