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