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