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 "Welcome, " + name + "!";
}
show(greet("Zoya")); (a) greet (b) Zoya (c) Welcome, Zoya! (d) Welcome, name! -
2.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Riya")); (a) Welcome, name! (b) greet (c) Welcome, Riya! (d) Riya -
3.🧰 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(1) + fee(7)); -
4.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(30, 6)); -
5.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(7)); -
6.🧰 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(8) + fee(1)); -
7.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Riya")); (a) Riya (b) greet (c) Hi, name! (d) Hi, Riya! -
8.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Kabir")); (a) Kabir (b) Hi, name! (c) Hi, Kabir! (d) greet - 9.🧰 What is a function? (a) a type of phone (b) a list of colours (c) a named block of code (d) a screen size
- 10.🧰 In function tip(bill), what is bill? (a) a loop (b) a screen (c) an event (d) a parameter
-
11.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(36)); -
12.🧰 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(4)); -
13.🧰 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(3)); -
14.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(75, 5)); - 15.🧰 Why write a function? (a) to hide errors (b) to reuse code (c) to slow the app (d) to make code longer
-
16.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(20)); -
17.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(40, 6)); -
18.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(0)); -
19.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(19)); -
20.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(32)); -
21.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Aman")); (a) greet (b) Hi, name! (c) Hi, Aman! (d) Aman -
22.🧰 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(9) + fee(2)); -
23.🧰 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(11) + fee(10)); -
24.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(27)); -
25.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Arjun")); (a) Hello, Arjun! (b) Hello, name! (c) Arjun (d) greet -
26.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(26)); -
27.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(75, 2)); -
28.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(45, 5)); -
29.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(18)); - 30.🧰 What does return do in a function? (a) sends back a value (b) deletes the app (c) closes the screen (d) repeats the code
-
31.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(50, 4)); -
32.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(70, 3)); -
33.🧰 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(12)); -
34.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Aman")); (a) Hello, name! (b) Aman (c) Hello, Aman! (d) greet -
35.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 3)); -
36.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(95, 2)); -
37.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(1)); -
38.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(8)); -
39.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(28)); -
40.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(16));
Answer key
- Welcome, Zoya!
- Welcome, Riya!
- 60
- 180
- 14
- 40
- Hi, Riya!
- Hi, Kabir!
- a named block of code
- a parameter
- 72
- 0
- 60
- 375
- to reuse code
- 40
- 240
- 50
- 38
- 64
- Hi, Aman!
- 60
- 60
- 81
- Hello, Arjun!
- 52
- 150
- 225
- 36
- sends back a value
- 200
- 210
- 60
- Hello, Aman!
- 105
- 190
- 30
- 24
- 56
- 32
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students