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