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