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