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("Riya")); (a) Well done, name! (b) Riya (c) greet (d) Well done, Riya! -
2.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(2)); -
3.🧰 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(8) + fee(7)); -
4.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(5)); -
5.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(55, 6)); -
6.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(9)); -
7.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(22)); -
8.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(10, 3)); - 9.🧰 In function tip(bill), what is bill? (a) a screen (b) an event (c) a parameter (d) a loop
-
10.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(40, 5)); -
11.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Aman")); (a) Aman (b) greet (c) Welcome, name! (d) Welcome, Aman! -
12.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(31)); -
13.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(4)); -
14.🧰 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(2) + fee(12)); -
15.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Zoya")); (a) Zoya (b) Hello, Zoya! (c) Hello, name! (d) greet -
16.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(34)); -
17.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(1)); -
18.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(4)); -
19.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(30, 2)); -
20.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Aman")); (a) Aman (b) greet (c) Hello, Aman! (d) Hello, name! -
21.🧰 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(6) + fee(9)); - 22.🧰 What does return do in a function? (a) repeats the code (b) deletes the app (c) sends back a value (d) closes the screen
-
23.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(3)); -
24.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(85, 5)); -
25.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(16)); -
26.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(5)); -
27.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(4)); -
28.🧰 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(12) + fee(5)); -
29.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(28)); - 30.🧰 What is a function? (a) a named block of code (b) a list of colours (c) a screen size (d) a type of phone
-
31.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(25, 2)); -
32.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(4)); -
33.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(85, 2)); -
34.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Arjun")); (a) greet (b) Welcome, name! (c) Welcome, Arjun! (d) Arjun -
35.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(2)); -
36.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(35)); -
37.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(37)); -
38.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Meera")); (a) Meera (b) Welcome, name! (c) greet (d) Welcome, Meera! -
39.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(2)); -
40.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(3));
Answer key
- Well done, Riya!
- 80
- 40
- 80
- 330
- 18
- 66
- 30
- a parameter
- 200
- Welcome, Aman!
- 93
- 70
- 40
- Hello, Zoya!
- 102
- 30
- 60
- 60
- Hello, Aman!
- 40
- sends back a value
- 60
- 425
- 32
- 70
- 100
- 100
- 84
- a named block of code
- 50
- 12
- 170
- Welcome, Arjun!
- 70
- 70
- 74
- Welcome, Meera!
- 50
- 90
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students