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