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