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