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