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