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