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