Skip to content

Commit 5c410d8

Browse files
fix: update comments and remove redundant variable declaration in convertToPercentage function
1 parent f5dc7fb commit 5c410d8

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
// Predict and explain first...
2+
// It will give you a percentage of 50% using the function by multiplying the 'decimalNumber' by 100 for the 'percentage' variables.
23

34
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
5+
// It will be a syntaxError because the 'decimalNumber' is already called in the function parameter.
56

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

9+
// function convertToPercentage(decimalNumber) {
10+
// const decimalNumber = 0.5;
11+
// const percentage = `${decimalNumber * 100}%`;
12+
13+
// return percentage;
14+
// }
15+
16+
// console.log(decimalNumber);
17+
18+
// decimalNumber in console.log isn't a defined number in the functions parameter now so it will return back as NaN "Not a Number", by adding '0.05' to the console.log it now has a number to calculate the percentage to
19+
20+
// Finally, correct the code to fix the problem
21+
22+
823
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
1024
const percentage = `${decimalNumber * 100}%`;
1125

1226
return percentage;
13-
}
14-
15-
console.log(decimalNumber);
1627

17-
// =============> write your explanation here
28+
}
1829

19-
// Finally, correct the code to fix the problem
20-
// =============> write your new code here
30+
console.log(convertToPercentage(0.5))

0 commit comments

Comments
 (0)