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