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