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