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.🧰 In function tip(bill), what is bill? (a) a parameter (b) a screen (c) an event (d) a loop
-
2.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(90, 5)); -
3.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(27)); -
4.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(4)); -
5.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Arjun")); (a) Hello, Arjun! (b) Hello, name! (c) Arjun (d) greet -
6.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(85, 2)); -
7.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(1)); - 8.🧰 What does return do in a function? (a) closes the screen (b) repeats the code (c) deletes the app (d) sends back a value
-
9.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(50, 5)); -
10.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(50, 2)); -
11.🧰 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(7) + fee(10)); -
12.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(0)); -
13.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(65, 5)); -
14.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 6)); -
15.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Riya")); (a) Welcome, name! (b) Welcome, Riya! (c) greet (d) Riya -
16.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(85, 4)); -
17.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Kabir")); (a) Hello, name! (b) Kabir (c) greet (d) Hello, Kabir! -
18.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(80, 4)); -
19.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Meera")); (a) greet (b) Meera (c) Hello, name! (d) Hello, Meera! -
20.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(12)); -
21.🧰 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(8) + fee(1)); -
22.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(3)); -
23.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(0)); -
24.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(6)); -
25.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(2)); -
26.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(1)); -
27.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(9)); -
28.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Arjun")); (a) Welcome, Arjun! (b) greet (c) Arjun (d) Welcome, name! -
29.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(19)); -
30.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(10)); -
31.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Zoya")); (a) Hi, name! (b) Hi, Zoya! (c) greet (d) Zoya - 32.🧰 Why write a function? (a) to hide errors (b) to slow the app (c) to reuse code (d) to make code longer
-
33.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(0)); -
34.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(5)); -
35.🧰 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(9)); -
36.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(90, 2)); -
37.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(65, 2)); -
38.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(4)); -
39.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(26)); -
40.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(17));
Answer key
- a parameter
- 450
- 81
- 100
- Hello, Arjun!
- 170
- 30
- sends back a value
- 250
- 100
- 120
- 40
- 325
- 90
- Welcome, Riya!
- 340
- Hello, Kabir!
- 320
- Hello, Meera!
- 36
- 60
- 50
- 50
- 18
- 40
- 50
- 18
- Welcome, Arjun!
- 57
- 20
- Hi, Zoya!
- to reuse code
- 20
- 80
- 50
- 180
- 130
- 70
- 52
- 51
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students