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