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