File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// Predict and explain first...
22
3- // Why will an error occur when this program runs?
4- // =============> write your prediction here
5-
3+ // Why will an error occur when this program runs
4+ // When this program runs there will be an identifier SyntaxError because 'decimalNumber' has already been declared
5+ // Also the output will print a decimal since it says console.log(decimalNumber);
66// Try playing computer with the example to work out what is going on
77
88function convertToPercentage ( decimalNumber ) {
9- const decimalNumber = 0.5 ;
109 const percentage = `${ decimalNumber * 100 } %` ;
1110
1211 return percentage ;
1312}
1413
15- console . log ( decimalNumber ) ;
14+ console . log ( convertToPercentage ( 0.5 ) ) ;
1615
17- // =============> write your explanation here
16+ // 'decimalNumber' is already declared in two different areas in the same function which JavaScript does not allow.
17+ // 'decimalNumber' is only useful inside the function, so it will give an error of not knowing what decimalNumber is,
18+ // even if it succeeds it will give the wrong output since what we are looking for is the percentage.
1819
1920// Finally, correct the code to fix the problem
20- // =============> write your new code here
21+ // New code: 1. Removed the duplicate `const decimalNumber = 0.5;` line.
22+ // 2. Changed the console.log to call the function and print the result.
You can’t perform that action at this time.
0 commit comments