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