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