Skip to content

Commit d0a3ed3

Browse files
committed
found 2 errors and changed code
1 parent 9fbfc91 commit d0a3ed3

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

  • Sprint-3/1-key-errors

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

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

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5+
// similar problem, the identifier has already been declared in function.
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+
// similar problem, the identifier 'decimalNumber" has already been declared in function and is a parameter.
20+
// we can then remove const decimalNumber, then function can also receive different numbers.
21+
// const percentage = `${decimalNumber * 100} %`;----> this calculates decimalNumber in which case it is 0.5 and multiply it by 100 which = 50 and then we add the % at the end which equals to 50%
22+
// another error is the console.log that exists outside the function and is tryng to log something that exists inside the function.
23+
// we want to print the result of the function we can ---> console.log(convertToPercentage(0.5));
1824

1925
// Finally, correct the code to fix the problem
2026
// =============> write your new code here
27+
28+
function convertToPercentage(decimalNumber) {
29+
const percentage = `${decimalNumber * 100}%`;
30+
31+
return percentage;
32+
}
33+
34+
console.log(convertToPercentage(0.5));

0 commit comments

Comments
 (0)