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