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