File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed
Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2+ // The code will give an error because `decimalNumber` is declared twice,
3+ // once as the function parameter, and again with `const` inside the function.
24
35// Why will an error occur when this program runs?
46// =============> write your prediction here
5-
7+ // The error occurs because `decimalNumber` has already been declared.
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 } %` ;
11-
12- return percentage ;
13- }
10+ // function convertToPercentage(decimalNumber) {
11+ // const decimalNumber = 0.5;
12+ // const percentage = `${decimalNumber * 100}%`;
1413
15- console . log ( decimalNumber ) ;
14+ // return percentage;
15+ // }
16+ // console.log(decimalNumber);
1617
1718// =============> write your explanation here
18-
19+ // When I run the code, it gives a SyntaxError saying that, `decimalNumber` has already been declared.
1920// Finally, correct the code to fix the problem
2021// =============> write your new code here
22+
23+ function convertToPercentage ( decimalNumber ) {
24+ const percentage = `${ decimalNumber * 100 } %` ;
25+ return percentage
26+ }
27+ console . log ( convertToPercentage ( 0.5 ) ) ;
You can’t perform that action at this time.
0 commit comments