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