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