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