File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
Expand file tree Collapse file tree 1 file changed +19
-3
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+ // =============> write your prediction here : The variable decimalNumber has been declared.
55
66// Try playing computer with the example to work out what is going on
77
8+ // The old code :
9+ /*
810function convertToPercentage(decimalNumber) {
911 const decimalNumber = 0.5;
1012 const percentage = `${decimalNumber * 100}%`;
@@ -13,8 +15,22 @@ function convertToPercentage(decimalNumber) {
1315}
1416
1517console.log(decimalNumber);
18+ */
1619
17- // =============> write your explanation here
18-
20+ // =============> write your explanation here :
21+ /*
22+ -The variable decimalNumber has been declared within the function as a parameter then declared again using const.
23+ - The variable decimalNumber should be defined first.
24+ */
1925// Finally, correct the code to fix the problem
2026// =============> write your new code here
27+
28+ //The correct code :
29+ const decimalNumber = 0.5 ;
30+
31+ function convertToPercentage ( decimalNumber ) {
32+ const percentage = `${ decimalNumber * 100 } %` ;
33+ return percentage ;
34+ }
35+
36+ console . log ( convertToPercentage ( decimalNumber ) ) ;
You can’t perform that action at this time.
0 commit comments