Skip to content

Commit 7916b12

Browse files
committed
key errors 1js
1 parent f5b9e81 commit 7916b12

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
// Predict and explain first...
22

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
5-
4+
// =============> write your prediction here decimalNumber has already been declared in the function. const can not redeclare a variable with the same name in the same scope. parameter, so we cannot declare it again with const.
5+
// This will cause a syntax error. To fix this, we should remove the const keyword when assigning the new value to decimalNumber.
6+
// console.log(decimalNumber); only exists inside the function.
67
// Try playing computer with the example to work out what is going on
78

8-
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
10-
const percentage = `${decimalNumber * 100}%`;
9+
//function convertToPercentage(decimalNumber) {
10+
//const decimalNumber = 0.5;
11+
//const percentage = `${decimalNumber * 100}%`;
1112

12-
return percentage;
13-
}
13+
//return percentage;
14+
//}
1415

15-
console.log(decimalNumber);
16+
//console.log(decimalNumber);
1617

1718
// =============> write your explanation here
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+
return percentage;
25+
}
26+
27+
console.log(convertToPercentage(0.5));

0 commit comments

Comments
 (0)