|
7 | 7 |
|
8 | 8 | // Try playing computer with the example to work out what is going on |
9 | 9 |
|
10 | | -function convertToPercentage(decimalNumber) { |
11 | | - // The parameter 'decimalNumber' is created as a variable inside the function's scope. |
12 | | - const decimalNumber = 0.5; |
13 | | - // tries to declare new variable called 'decimalNumber' in the same scope, where one already exists as a parameter |
14 | | - // cannot declare same name twice in one scope with 'const' |
15 | | - const percentage = `${decimalNumber * 100}%`; |
| 10 | +// function convertToPercentage(decimalNumber) { |
| 11 | +// // The parameter 'decimalNumber' is created as a variable inside the function's scope. |
| 12 | +// const decimalNumber = 0.5; |
| 13 | +// // tries to declare new variable called 'decimalNumber' in the same scope, where one already exists as a parameter |
| 14 | +// // cannot declare same name twice in one scope with 'const' |
| 15 | +// const percentage = `${decimalNumber * 100}%`; |
16 | 16 |
|
17 | | - return percentage; |
18 | | -} |
19 | | -// As a result of the conflict nothing runs. |
20 | | -console.log(decimalNumber); |
21 | | -// This line is outside the function and would not parse, as 'decimalNumber' only exists inside 'convertToPercentage' as a parameter. |
| 17 | +// return percentage; |
| 18 | +// } |
| 19 | +// // As a result of the conflict nothing runs. |
| 20 | +// console.log(decimalNumber); |
| 21 | +// // This line is outside the function and would not parse, as 'decimalNumber' only exists inside 'convertToPercentage' as a parameter. |
22 | 22 |
|
23 | 23 | // =============> write your explanation here |
24 | 24 | // Parameters and variables declared inside a function cannot be accessed outside it. |
25 | | - |
| 25 | + |
26 | 26 | // Finally, correct the code to fix the problem |
27 | 27 | // =============> write your new code here |
0 commit comments