Skip to content

Commit 8d94e35

Browse files
committed
Refactor comments to clarify error prediction and explanation for convertToPercentage function
1 parent c9f5c3b commit 8d94e35

File tree

1 file changed

+12
-3
lines changed
  • Sprint-2/1-key-errors

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Predict and explain first...
2-
2+
// I predict that the code will throw an error when trying to call the function convertToPercentage with a decimal input
3+
// because the variable 'decimalNumber' is being declared twice within the same scope, which is not allowed in JavaScript.
34
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
5+
// The code will throw a SyntaxError because the variable 'decimalNumber' is being declared twice within the same scope.
6+
7+
58

69
// Try playing computer with the example to work out what is going on
710

@@ -16,5 +19,11 @@ console.log(decimalNumber);
1619

1720
// =============> write your explanation here
1821

19-
// Finally, correct the code to fix the problem
22+
// The code will throw a SyntaxError because the variable 'decimalNumber' is being declared twice within the same scope.
2023
// =============> write your new code here
24+
25+
function convertToPercentage(decimalNumber) {
26+
decimalNumber = 0.5;
27+
const percentage = `${decimalNumber * 100}%`;
28+
29+
return percentage;

0 commit comments

Comments
 (0)