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