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