Skip to content

Commit 7cd8ae3

Browse files
committed
fix percentage conversion variable redeclaration
1 parent a729eff commit 7cd8ae3

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

  • Sprint-3/1-key-errors

‎Sprint-3/1-key-errors/1.js‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// Predict and explain first...
1+
// Predict and explain first...:It doesn't run.We have a syntaxError.
22

3-
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
3+
// Why will an error occur when this program runs?because decimalNumber is declared.
4+
// as a parameter and then declared again using const.
5+
6+
// =============> write your prediction here:We will have a SyntaxError because decimalNumber is a parameter of the function, but it is declared again using const inside the function.
57

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

@@ -14,7 +16,14 @@ function convertToPercentage(decimalNumber) {
1416

1517
console.log(decimalNumber);
1618

17-
// =============> write your explanation here
19+
// =============> write your explanation here:decimalNumber is inside the function, so we can not use it outside the function.
1820

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

0 commit comments

Comments
 (0)