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