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