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