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