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