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