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 total(price, qty) {
return price * qty;
}
show(total(85, 3)); -
2.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(3)); - 3.🧰 In function tip(bill), what is bill? (a) a screen (b) a loop (c) an event (d) a parameter
-
4.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 3)); -
5.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Aman")); (a) Aman (b) Hi, Aman! (c) Hi, name! (d) greet -
6.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(40)); -
7.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(0)); -
8.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(90, 6)); -
9.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(4)); -
10.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(1)); - 11.🧰 How do you run (call) a function called greet? (a) run greet (b) #greet (c) greet[] (d) greet()
-
12.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Kabir")); (a) Kabir (b) Hi, Kabir! (c) Hi, name! (d) greet -
13.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 50;
}
show(fee(1) + fee(6)); -
14.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(45, 2)); -
15.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Kabir")); (a) Hello, name! (b) Kabir (c) greet (d) Hello, Kabir! -
16.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 2)); -
17.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Riya")); (a) Welcome, name! (b) Riya (c) Welcome, Riya! (d) greet -
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(12) + fee(4)); - 19.🧰 What does return do in a function? (a) closes the screen (b) sends back a value (c) deletes the app (d) repeats the code
-
20.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 3)); -
21.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(0)); -
22.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(2)); -
23.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Meera")); (a) Meera (b) greet (c) Welcome, Meera! (d) Welcome, name! -
24.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(1)); -
25.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(1)); -
26.🧰 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(5)); -
27.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Kabir")); (a) greet (b) Well done, Kabir! (c) Kabir (d) Well done, name! -
28.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(34)); - 29.🧰 What is a function? (a) a list of colours (b) a type of phone (c) a screen size (d) a named block of code
-
30.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(0)); -
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(12) + fee(6)); -
32.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Arjun")); (a) greet (b) Arjun (c) Well done, name! (d) Well done, Arjun! -
33.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(39)); -
34.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(95, 5)); -
35.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(3)); -
36.🧰 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(10) + fee(10)); -
37.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Zoya")); (a) Hello, name! (b) Hello, Zoya! (c) Zoya (d) greet -
38.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(4)); -
39.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(5)); -
40.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(4));
Answer key
- 255
- 9
- a parameter
- 105
- Hi, Aman!
- 80
- 20
- 540
- 8
- 60
- greet()
- Hi, Kabir!
- 50
- 90
- Hello, Kabir!
- 30
- Welcome, Riya!
- 60
- sends back a value
- 45
- 60
- 70
- Welcome, Meera!
- 30
- 40
- 30
- Well done, Kabir!
- 102
- a named block of code
- 50
- 60
- Well done, Arjun!
- 117
- 475
- 80
- 120
- Hello, Zoya!
- 60
- 90
- 100
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students