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