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(45, 6)); -
2.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(2)); -
3.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(4)); -
4.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Meera")); (a) Well done, name! (b) greet (c) Well done, Meera! (d) Meera -
5.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Riya")); (a) Well done, Riya! (b) Riya (c) Well done, name! (d) greet -
6.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(20)); - 7.🧰 Why write a function? (a) to reuse code (b) to hide errors (c) to slow the app (d) to make code longer
-
8.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(5)); - 9.🧰 What is a function? (a) a named block of code (b) a list of colours (c) a screen size (d) a type of phone
-
10.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 2)); -
11.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(3)); -
12.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(0)); -
13.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(0)); -
14.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Zoya")); (a) Welcome, name! (b) greet (c) Zoya (d) Welcome, Zoya! -
15.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(55, 2)); -
16.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(5)); - 17.🧰 In function tip(bill), what is bill? (a) an event (b) a loop (c) a screen (d) a parameter
-
18.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 20;
}
show(fee(1) + fee(11)); -
19.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(22)); -
20.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(1)); -
21.🧰 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(3) + fee(6)); -
22.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(2)); -
23.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(1)); -
24.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 4)); -
25.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(3)); -
26.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Aman")); (a) Welcome, Aman! (b) Welcome, name! (c) greet (d) Aman -
27.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(10, 4)); -
28.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(32)); -
29.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 4)); -
30.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(5)); -
31.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Kabir")); (a) Kabir (b) greet (c) Hello, Kabir! (d) Hello, name! -
32.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(75, 4)); -
33.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(25, 6)); -
34.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Arjun")); (a) Hi, name! (b) greet (c) Arjun (d) Hi, Arjun! -
35.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(37)); -
36.🧰 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(8)); -
37.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(25)); -
38.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Aman")); (a) Hello, name! (b) Hello, Aman! (c) greet (d) Aman -
39.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Riya")); (a) Riya (b) greet (c) Welcome, name! (d) Welcome, Riya! -
40.🧰 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(5) + fee(5));
Answer key
- 270
- 70
- 100
- Well done, Meera!
- Well done, Riya!
- 60
- to reuse code
- 80
- a named block of code
- 70
- 80
- 30
- 50
- Welcome, Zoya!
- 110
- 110
- a parameter
- 20
- 44
- 60
- 50
- 60
- 40
- 60
- 9
- Welcome, Aman!
- 40
- 96
- 140
- 15
- Hello, Kabir!
- 300
- 150
- Hi, Arjun!
- 74
- 60
- 50
- Hello, Aman!
- Welcome, Riya!
- 80
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students