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