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