-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy path1.js
More file actions
27 lines (19 loc) · 844 Bytes
/
1.js
File metadata and controls
27 lines (19 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Predict and explain first...
// Why will an error occur when this program runs?
// =============> because first: the variable decimalNumber is declared twice
// second: the parameter decimalNumber is assigned to a value inside the function
// Try playing computer with the example to work out what is going on
function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;
return percentage;
}
console.log(decimalNumber);
// =============> Identifier 'decimalNumber' has already been declared is the error msg thrown by the code
// Finally, correct the code to fix the problem
// =============>
function convertToPercentage(decimalNumber) {
// const decimalNumber = 0.5; this line must be deleted
const percentage = `${decimalNumber * 100}%`;
return percentage;
}