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