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