Skip to content

Commit df6c2f8

Browse files
Correct variable scope and console log usage
Fixed variable declaration issue in convertToPercentage function and updated console log.
1 parent ff84a76 commit df6c2f8

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

  • Sprint-2/1-key-errors

Sprint-2/1-key-errors/1.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// Predict and explain first...
2-
32
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
3+
// =============> The error will appear because we are trying to log the variable decimalNumber in the function. We have to call the function at this point. Besides to that, the decimalNumber is again declared inside the function where it shouldn't be.
4+
55

66
// Try playing computer with the example to work out what is going on
77

8+
89
function convertToPercentage(decimalNumber) {
910
const decimalNumber = 0.5;
1011
const percentage = `${decimalNumber * 100}%`;
1112

13+
1214
return percentage;
1315
}
1416

15-
console.log(decimalNumber);
1617

17-
// =============> write your explanation here
18+
console.log(decimalNumber);
1819

19-
// Finally, correct the code to fix the problem
20-
// =============> write your new code here

0 commit comments

Comments
 (0)