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