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