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