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