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