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