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