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