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