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