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