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