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