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