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