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