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