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