File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33// Why will an error occur when this program runs?
44// =============> write your prediction here
55
6+ // Prediction:
7+ // 1. decimalNumber is declared twice and it will give syntax error.
8+
69// Try playing computer with the example to work out what is going on
710
8- function convertToPercentage ( decimalNumber ) {
11+ /* function convertToPercentage(decimalNumber) {
912 const decimalNumber = 0.5;
1013 const percentage = `${decimalNumber * 100}%`;
1114
1215 return percentage;
1316}
1417
15- console . log ( decimalNumber ) ;
18+ console.log(decimalNumber);*/
1619
1720// =============> write your explanation here
1821
22+ // 2. console.log will return undefined as decimalNumber local scope declaration inside the function.
23+ // 3. It's percentage not decimalNumber needs printing.
24+
1925// Finally, correct the code to fix the problem
2026// =============> write your new code here
27+
28+ function convertToPercentage ( decimalNumber ) {
29+ return percentage = `${ decimalNumber * 100 } %` ;
30+ }
31+
32+ console . log ( convertToPercentage ( 0.5 ) ) ;
33+
34+ // The function convertToPercentage can be called passing with an argument of the input.
You can’t perform that action at this time.
0 commit comments