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