|
1 | 1 | // Predict and explain first... |
2 | | - |
3 | | -// Why will an error occur when this program runs? |
| 2 | +// error on line 11 |
| 3 | +// error on line 17 |
| 4 | +// Why will an error occur when this program runs? yes |
4 | 5 | // =============> write your prediction here |
| 6 | +// decimalNumber is declared before and can not be declared again. |
| 7 | +// console.log(decimalNumber) should be console.log(convertToPercentage) |
| 8 | +// Try playing computer with the example to work ot what is going on |
5 | 9 |
|
6 | | -// Try playing computer with the example to work out what is going on |
7 | | - |
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}%`; |
11 | 13 |
|
12 | | - return percentage; |
13 | | -} |
| 14 | +// return percentage; |
| 15 | +// } |
14 | 16 |
|
15 | | -console.log(decimalNumber); |
| 17 | +//console.log(percentage); |
16 | 18 |
|
17 | 19 | // =============> write your explanation here |
| 20 | +// decimalNumber is declared before and can not be declared again. |
| 21 | +// console.log(decimalNumber) should be console.log(convertToPercentage) |
18 | 22 |
|
19 | 23 | // Finally, correct the code to fix the problem |
20 | 24 | // =============> write your new code here |
| 25 | +function convertToPercentage(decimalNumber) { |
| 26 | + //const decimalNumber = 0.5; |
| 27 | + const percentage = `${decimalNumber * 100}%`; |
| 28 | + |
| 29 | + return percentage; |
| 30 | +} |
| 31 | + |
| 32 | +console.log(convertToPercentage(0.5)); |
0 commit comments