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