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