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