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