File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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+ // =============> I think when we run the programme it will show the type error because decimal number is reassigning inside the function.
55
66// Try playing computer with the example to work out what is going on
77
8- function convertToPercentage ( decimalNumber ) {
9- const decimalNumber = 0.5 ;
10- const percentage = `${ decimalNumber * 100 } %` ;
8+ // function convertToPercentage(decimalNumber) {
9+ // const decimalNumber = 0.5;
10+ // const percentage = `${decimalNumber * 100}%`;
1111
12- return percentage ;
13- }
12+ // return percentage;
13+ // }
1414
15- console . log ( decimalNumber ) ;
15+ // console.log(decimalNumber);
1616
1717// =============> write your explanation here
18-
18+ // while running this function is shows typeerror because decimal number variable is declared two times.
19+ // and in step 15 we need call function name not decimal number.
1920// Finally, correct the code to fix the problem
2021// =============> write your new code here
22+ function convertToPercentage ( decimalNumber ) {
23+
24+ const percentage = `${ decimalNumber * 100 } %` ;
25+
26+ return percentage ;
27+ }
28+
29+ console . log ( convertToPercentage ( 0.5 ) ) ;
30+ // After solving this the output is 50%.
You can’t perform that action at this time.
0 commit comments