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