Skip to content

Commit ad0f006

Browse files
committed
Answering the task
1 parent f070a00 commit ad0f006

File tree

1 file changed

+19
-7
lines changed
  • Sprint-2/1-key-errors

1 file changed

+19
-7
lines changed

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> I believe that the function converToPercentage is not mentioned in the console.log statement.
5+
// Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage.
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+
// return percentage;
1314
}
1415

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

17-
// =============> write your explanation here
18+
// =============> A syntaxError occurred saying decimalNumber is already declared.
1819

1920
// Finally, correct the code to fix the problem
2021
// =============> write your new code here
22+
23+
function convertToPercentage() {
24+
const decimalNumber = 0.5;
25+
const percentage = `${decimalNumber * 100}%`;
26+
27+
return percentage;
28+
}
29+
30+
console.log(convertToPercentage());
31+
32+
// the new code runs without error and outputs "50%"

0 commit comments

Comments
 (0)