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