File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed
Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2+ // program is made for converting a decimal number into a percentage.
23
34// Why will an error occur when this program runs?
4- // =============> write your prediction here
5+ // =============> I think error would occur because decimalNumber is declared twice.
56
67// Try playing computer with the example to work out what is going on
78
@@ -14,7 +15,15 @@ function convertToPercentage(decimalNumber) {
1415
1516console . log ( decimalNumber ) ;
1617
17- // =============> write your explanation here
18+ // =============> to fix the problem I will remove the second declaration of decimalNumber and use the parameter instead.
1819
1920// Finally, correct the code to fix the problem
20- // =============> write your new code here
21+ // =============>
22+ function convertToPercentage ( decimalNumber ) {
23+ const percentage = `${ decimalNumber * 100 } %` ;
24+
25+ return percentage ;
26+ }
27+
28+ // to call the function
29+ console . log ( convertToPercentage ( 1 ) ) ; // Output: "100%"
Original file line number Diff line number Diff line change 33
44// this function should square any number but instead we're going to get an error
55
6- // =============> write your prediction of the error here
6+ // =============> My prediction is that error occurs because function trying to use a number as a function.
77
88function square ( 3 ) {
99 return num * num ;
1010}
1111
12- // =============> write the error message here
12+ // =============> Expected identifier but found "3"
1313
14- // =============> explain this error message here
14+ // =============> While program waiting for an identifier, it found a number instead.
1515
1616// Finally, correct the code to fix the problem
1717
18- // =============> write your new code here
18+ // =============>
19+ function square ( num ) {
20+ return num * num ;
21+ }
22+
23+ // to call the function
24+ console . log ( square ( 9 ) ) ; // Output: 81
1925
2026
You can’t perform that action at this time.
0 commit comments