Skip to content

Commit a0786f8

Browse files
committed
Answered teh question for 1.js and added in code to fix it.
1 parent 49088fa commit a0786f8

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

  • Sprint-3/1-key-errors

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

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

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5+
// decimalNumber is part of the function so it cant be set with const decimalNumber, the name needs to be different.
6+
// console.log(decimalNumber) causes an issue as well, decimalNumber is part of the function, it should request convertToPercentage for it to work.
57

68
// Try playing computer with the example to work out what is going on
79

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

12-
return percentage;
13-
}
14+
// return percentage;
15+
// }
1416

15-
console.log(decimalNumber);
17+
// console.log(decimalNumber);
1618

1719
// =============> write your explanation here
20+
// console.log(decimalNumber) will not work as decimalNumber is inside the function,
21+
// and "const devimalNumber = 0.5" has already been called from teh function. You need to change the name or apply the value in the call on consol.log()
22+
1823

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

0 commit comments

Comments
 (0)