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