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