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