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