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