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