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