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