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