File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed
Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change 22
33// Why will an error occur when this program runs?
44// =============> write your prediction here
5+ // PREDICTION: There will be a SyntaxError because 'decimalNumber' is declared twice - once as parameter, once as variable
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
18-
19+ // Cannot redeclare 'decimalNumber' with 'const' inside function - it's already the parameter name
1920// Finally, correct the code to fix the problem
2021// =============> write your new code here
22+ function convertToPercentage ( decimalNumber ) {
23+ const percentage = `${ decimalNumber * 100 } %` ;
24+
25+ return percentage ;
26+ }
27+
28+ console . log ( convertToPercentage ( 0.5 ) ) ;
You can’t perform that action at this time.
0 commit comments