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) greet() (c) #greet (d) run greet
-
2.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 4)); - 3.🧰 What is a function? (a) a list of colours (b) a screen size (c) a named block of code (d) a type of phone
-
4.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(95, 6)); -
5.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Riya")); (a) greet (b) Riya (c) Hello, Riya! (d) Hello, name! -
6.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(25, 3)); -
7.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 4)); -
8.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(4)); -
9.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(5)); - 10.🧰 Why write a function? (a) to make code longer (b) to reuse code (c) to hide errors (d) to slow the app
-
11.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Meera")); (a) Hello, Meera! (b) greet (c) Hello, name! (d) Meera -
12.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(10)); -
13.🧰 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(12) + fee(7)); -
14.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(13)); -
15.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(25, 6)); -
16.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Arjun")); (a) Arjun (b) greet (c) Hi, Arjun! (d) Hi, name! -
17.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Riya")); (a) greet (b) Well done, Riya! (c) Well done, name! (d) Riya -
18.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(17)); -
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 points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(3)); -
21.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(35)); -
22.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(60, 6)); -
23.🧰 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(10) + fee(2)); -
24.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(80, 3)); -
25.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Zoya")); (a) Zoya (b) Hi, Zoya! (c) greet (d) Hi, name! -
26.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Kabir")); (a) Welcome, Kabir! (b) Kabir (c) greet (d) Welcome, name! - 27.🧰 In function tip(bill), what is bill? (a) a parameter (b) an event (c) a screen (d) a loop
-
28.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(37)); -
29.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(1)); -
30.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(11)); -
31.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(100, 2)); -
32.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(1)); -
33.🧰 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(1) + fee(3)); -
34.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(90, 3)); -
35.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(0)); -
36.🧰 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(3)); -
37.🧰 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(7)); -
38.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(90, 5)); -
39.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(22)); -
40.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(2));
Answer key
- greet()
- 60
- a named block of code
- 570
- Hello, Riya!
- 75
- 140
- 90
- 100
- to reuse code
- Hello, Meera!
- 30
- 120
- 26
- 150
- Hi, Arjun!
- Well done, Riya!
- 34
- 60
- 60
- 105
- 360
- 20
- 240
- Hi, Zoya!
- Welcome, Kabir!
- a parameter
- 74
- 50
- 22
- 200
- 70
- 0
- 270
- 20
- 40
- 100
- 450
- 66
- 40
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students