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