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.🧰 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(3) + fee(8)); -
2.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(3)); -
3.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(2)); -
4.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(90, 3)); -
5.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Meera")); (a) greet (b) Well done, Meera! (c) Meera (d) Well done, name! -
6.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(70, 3)); -
7.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(0)); - 8.🧰 How do you run (call) a function called greet? (a) #greet (b) greet() (c) greet[] (d) run greet
-
9.🧰 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(2) + fee(5)); -
10.🧰 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(7)); -
11.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(55, 3)); -
12.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(1)); -
13.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Aman")); (a) Aman (b) Hello, name! (c) greet (d) Hello, Aman! -
14.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(20, 5)); -
15.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 6)); -
16.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(18)); -
17.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(25, 4)); -
18.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(30, 3)); -
19.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(10, 2)); -
20.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(60, 5)); -
21.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(0)); -
22.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(12)); -
23.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Arjun")); (a) Arjun (b) greet (c) Welcome, Arjun! (d) Welcome, name! -
24.🧰 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! - 25.🧰 In function tip(bill), what is bill? (a) an event (b) a screen (c) a loop (d) a parameter
-
26.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(50, 6)); -
27.🧰 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(5) + fee(7)); - 28.🧰 Why write a function? (a) to make code longer (b) to slow the app (c) to hide errors (d) to reuse code
-
29.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(23)); -
30.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(17)); -
31.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 4)); -
32.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Aman")); (a) greet (b) Hi, name! (c) Hi, Aman! (d) Aman -
33.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Riya")); (a) greet (b) Riya (c) Hi, Riya! (d) Hi, name! -
34.🧰 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(10) + fee(12)); -
35.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(39)); -
36.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Riya")); (a) Well done, Riya! (b) Riya (c) Well done, name! (d) greet -
37.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Riya")); (a) Hello, name! (b) Riya (c) greet (d) Hello, Riya! -
38.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(40, 3)); -
39.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(3)); -
40.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Kabir")); (a) greet (b) Kabir (c) Hi, Kabir! (d) Hi, name!
Answer key
- 50
- 50
- 80
- 270
- Well done, Meera!
- 210
- 40
- greet()
- 60
- 80
- 165
- 70
- Hello, Aman!
- 100
- 210
- 36
- 100
- 90
- 20
- 300
- 50
- 36
- Welcome, Arjun!
- Well done, Arjun!
- a parameter
- 300
- 60
- to reuse code
- 69
- 34
- 140
- Hi, Aman!
- Hi, Riya!
- 100
- 117
- Well done, Riya!
- Hello, Riya!
- 120
- 6
- Hi, Kabir!
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students