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