Skip to content

Commit c00019f

Browse files
committed
completed tasks in 1-key-errors/1.js
1 parent 0ffaae1 commit c00019f

File tree

1 file changed

+15
-6
lines changed
  • Sprint-2/1-key-errors

1 file changed

+15
-6
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@
22

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5+
//There are two errors in the code. Firstly the variable decimalNumber is being used as a parameter to the function but is then redeclared in the function. Secondly the console log is trying to access a variable that is not in its scope.
56

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
19+
//line 9 creates a a new variable called decimal number, then on line 10 the code attempts to declare a new variable with the same name and thus a syntax error is thrown.
1820

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

0 commit comments

Comments
 (0)