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