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