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