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