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