File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Expand file tree Collapse file tree 1 file changed +19
-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+ // =============> I believe that the function converToPercentage is not mentioned in the console.log statement.
5+ // Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage.
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+ // return percentage;
1314}
1415
15- console . log ( decimalNumber ) ;
16+ // console.log(decimalNumber);
1617
17- // =============> write your explanation here
18+ // =============> A syntaxError occurred saying decimalNumber is already declared.
1819
1920// Finally, correct the code to fix the problem
2021// =============> write your new code here
22+
23+ function convertToPercentage ( ) {
24+ const decimalNumber = 0.5 ;
25+ const percentage = `${ decimalNumber * 100 } %` ;
26+
27+ return percentage ;
28+ }
29+
30+ console . log ( convertToPercentage ( ) ) ;
31+
32+ // the new code runs without error and outputs "50%"
You can’t perform that action at this time.
0 commit comments