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