Skip to content

Commit bf6d021

Browse files
Update comments to clarify reference error and correct function implementation in convertToPercentage
1 parent b86d1d1 commit bf6d021

File tree

1 file changed

+17
-7
lines changed
  • Sprint-2/1-key-errors

1 file changed

+17
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
// Predict and explain first...
22

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> It will likely be a reference error because the variable decimalNumber is not defined in the global scope
5+
// and is only declared within the function convertToPercentage. When we try to log decimalNumber outside of the function,
6+
// it will not be accessible and will throw an error indicating that decimalNumber is not defined.
57

68
// Try playing computer with the example to work out what is going on
79

8-
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
10-
const percentage = `${decimalNumber * 100}%`;
10+
//function convertToPercentage(decimalNumber) {
11+
//const decimalNumber = 0.5;
12+
//const percentage = `${decimalNumber * 100}%`;
1113

12-
return percentage;
13-
}
14+
//return percentage;
15+
//}
1416

15-
console.log(decimalNumber);
17+
//console.log(decimalNumber);
1618

1719
// =============> write your explanation here
1820

1921
// Finally, correct the code to fix the problem
2022
// =============> write your new code here
23+
24+
function convertToPercentage(a) {
25+
const decimalNumber = 0.5;
26+
const percentage = `${decimalNumber * 100}%`;
27+
28+
return percentage;
29+
}
30+
console.log(convertToPercentage(0.5));

0 commit comments

Comments
 (0)