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