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