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