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