File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2-
2+ // I predict that the code will throw an error when trying to call the function convertToPercentage with a decimal input
3+ // because the variable 'decimalNumber' is being declared twice within the same scope, which is not allowed in JavaScript.
34// Why will an error occur when this program runs?
4- // =============> write your prediction here
5+ // The code will throw a SyntaxError because the variable 'decimalNumber' is being declared twice within the same scope.
6+
7+
58
69// Try playing computer with the example to work out what is going on
710
@@ -16,5 +19,11 @@ console.log(decimalNumber);
1619
1720// =============> write your explanation here
1821
19- // Finally, correct the code to fix the problem
22+ // The code will throw a SyntaxError because the variable 'decimalNumber' is being declared twice within the same scope.
2023// =============> write your new code here
24+
25+ function convertToPercentage ( decimalNumber ) {
26+ decimalNumber = 0.5 ;
27+ const percentage = `${ decimalNumber * 100 } %` ;
28+
29+ return percentage ;
You can’t perform that action at this time.
0 commit comments