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