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