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