File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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+ /*When this program runs, there will be two errors: the function redeclares decimalNumber,
6+ and decimalNumber is used in console.log even though it is not defined outside the function.*/
57
68// Try playing computer with the example to work out what is going on
79
8- function convertToPercentage ( decimalNumber ) {
10+ /* function convertToPercentage(decimalNumber) {
911 const decimalNumber = 0.5;
1012 const percentage = `${decimalNumber * 100}%`;
1113
1214 return percentage;
1315}
1416
15- console . log ( decimalNumber ) ;
17+ console.log(decimalNumber);*/
1618
1719// =============> write your explanation here
20+ // When I run this code, I get a SyntaxError because decimalNumber is already declared inside the function.
1821
1922// Finally, correct the code to fix the problem
2023// =============> write your new code here
24+
25+ function convertToPercentage ( decimalNumber ) {
26+ const percentage = `${ decimalNumber * 100 } %` ;
27+ return percentage ;
28+ }
29+ console . log ( convertToPercentage ( 0.5 ) ) ;
30+ console . log ( convertToPercentage ( 0.45 ) ) ;
You can’t perform that action at this time.
0 commit comments