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