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