Skip to content

Commit e838340

Browse files
committed
Fix convertToPercentage function; now returns correct 50% output
1 parent 7291d85 commit e838340

File tree

1 file changed

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

1 file changed

+9
-1
lines changed

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> write your prediction here
5+
// the error occur because the decimalNumber has already been declared.
56

67
// Try playing computer with the example to work out what is going on
78

@@ -15,6 +16,13 @@ function convertToPercentage(decimalNumber) {
1516
console.log(decimalNumber);
1617

1718
// =============> write your explanation here
19+
// I tried to run the code it gives me SyntaxError,that the decimalNumber has already been declared, we can see in the parameter already has name decimalNumber.
20+
// thats why declaring it again inside the function, causes an error.
1821

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

0 commit comments

Comments
 (0)