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