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