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