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