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