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