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