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