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