Skip to content

Commit 32beae4

Browse files
Fix redeclaration and return value in convertToPercentage
Refactor convertToPercentage function to avoid redeclaration and return correct percentage.
1 parent 1c3dd05 commit 32beae4

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

  • Sprint-2/1-key-errors

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,23 @@
55

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

8-
98
function convertToPercentage(decimalNumber) {
10-
return `${decimalNumber * 100}%`;
11-
}
12-
13-
console.log(convertToPercentage(0.1));
9+
const decimalNumber = 0.5;
10+
const percentage = `${decimalNumber * 100}%`;
1411

12+
return percentage;
13+
}
1514

1615
console.log(decimalNumber);
1716
// =============> it says decimalNumber has aleady been declared for the above reason.
1817

1918

2019
// Finally, correct the code to fix the problem
2120
/* ===========> function convertToPercentage(decimalNumber) {
22-
let decimalNum = 0.5;
23-
const percentage = `${decimalNum * 100}%`;
24-
25-
26-
return percentage;
21+
const result = `${decimalNumber * 100}%`;
22+
return result;
2723
}
28-
const result = convertToPercentage();
29-
console.log(result);
24+
console.log(convertToPercentage(0.1));
3025
*/
3126

3227

0 commit comments

Comments
 (0)