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