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