File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed
Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22
33// Why will an error occur when this program runs?
4- // =============> write your prediction here
4+ // =============> It will likely be a reference error because the variable decimalNumber is not defined in the global scope
5+ // and is only declared within the function convertToPercentage. When we try to log decimalNumber outside of the function,
6+ // it will not be accessible and will throw an error indicating that decimalNumber is not defined.
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
1820
1921// Finally, correct the code to fix the problem
2022// =============> write your new code here
23+
24+ function convertToPercentage ( a ) {
25+ const decimalNumber = 0.5 ;
26+ const percentage = `${ decimalNumber * 100 } %` ;
27+
28+ return percentage ;
29+ }
30+ console . log ( convertToPercentage ( 0.5 ) ) ;
You can’t perform that action at this time.
0 commit comments