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