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