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