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