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