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