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