-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.js
More file actions
34 lines (21 loc) · 934 Bytes
/
Copy path1.js
File metadata and controls
34 lines (21 loc) · 934 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
28
29
30
31
32
33
34
// Predict and explain first...
// Why will an error occur when this program runs?
// =============> I think, the function convertToPercentage is not called at line 16, and
// there is no any importance of declaring cons decimalNumber as it is already declared.
// 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);
// =============> A syntaxError appeared indicating 'decimalNumber' has already been declared.
// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage() {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;
return percentage;
}
console.log(convertToPercentage());
// The new code run smoothly and retuned "50%"