File tree Expand file tree Collapse file tree 1 file changed +27
-5
lines changed
Expand file tree Collapse file tree 1 file changed +27
-5
lines changed 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- // Try playing computer with the example to work out what is going on
3+ /*
54
6- function convertToPercentage ( decimalNumber ) {
7- const decimalNumber = 0.5 ;
5+ Why will an error occur when this program runs?
6+ Try playing computer with the example to work out what is going on
7+
8+ 1. The function won't run because we are not invoking the function,
9+ 2. we have been declared one variable with const and this can not reassigned after, const decimalNumber also has a fixed value
10+ 3. To work efficiently we should assign the parameter =+ inside the function and declare the var decimalNumber
11+ 4. we call the function correctly with its respective argument
12+
13+ function convertToPercentage(decimalNumber) {
14+ const decimalNumber = 0.5;
15+ const percentage = `${decimalNumber * 100}%`;
16+
17+ return percentage;
18+ }
19+
20+ console.log(decimalNumber);
21+ */
22+
23+
24+ /*================== fixed =======================*/
25+
26+ function convertToPercentage ( num ) {
27+ const decimalNumber = num ;
828 const percentage = `${ decimalNumber * 100 } %` ;
929
1030 return percentage ;
1131}
1232
13- console . log ( decimalNumber ) ;
33+ console . log ( convertToPercentage ( .2 ) ) ; //20%
34+
35+
You can’t perform that action at this time.
0 commit comments