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