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