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