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