Skip to content

Commit 7570924

Browse files
committed
Fixed variable redeclaration in convertToPercentage function and update comments for clarity
1 parent 2076556 commit 7570924

File tree

1 file changed

+9
-2
lines changed
  • Sprint-2/1-key-errors

1 file changed

+9
-2
lines changed

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> The variable decimalNumber has been declared twice and will retun an error.
55

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

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

1515
console.log(decimalNumber);
1616

17-
// =============> write your explanation here
17+
// =============> The variable decimalNumber has been declared twice and returned an error saying it had already been declared. There is also a console log error as it is trying to use a variable that is inside the function and hasn't been declared outside.
18+
1819

1920
// Finally, correct the code to fix the problem
2021
// =============> write your new code here
22+
function convertToPercentage(decimalNumber) {
23+
const percentage = `${decimalNumber * 100}%`;
24+
console.log(percentage);
25+
return percentage;
26+
}
27+
//We can also use console log inside the function.

0 commit comments

Comments
 (0)