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