File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,5 +9,10 @@ function capitalise(str) {
99 return str ;
1010}
1111
12- // =============> write your explanation here
13- // =============> write your new code here
12+ // The error is on line 8.
13+ // The parameter 'str' has already been declared in the function.
14+ // Declaring 'let str' again causes the error.
15+ function capitalise ( str ) {
16+ let capitalisedStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
17+ return capitalisedStr ;
18+ }
Original file line number Diff line number Diff line change @@ -14,7 +14,13 @@ function convertToPercentage(decimalNumber) {
1414
1515console . log ( decimalNumber ) ;
1616
17- // =============> write your explanation here
17+ // The parameter decimalNumber is already declared.
18+ // Declaring const decimalNumber again causes the error.
1819
1920// Finally, correct the code to fix the problem
20- // =============> write your new code here
21+ function convertToPercentage ( decimalNumber ) {
22+ const percentage = `${ decimalNumber * 100 } %` ;
23+ return percentage ;
24+ }
25+
26+ console . log ( convertToPercentage ( 0.5 ) ) ;
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+ // function parameter should not be a number, it should be a variable name that holds a number.
7+ // the parameter is a placeholder for the number.
78
89function square ( 3 ) {
910 return num * num ;
1011}
1112
12- // =============> write the error message here
13+ // SyntaxError: Unexpected number
1314
14- // =============> explain this error message here
15+ // The error occurs because a function parameter must be a variable name, not a number.
1516
1617// Finally, correct the code to fix the problem
1718
18- // =============> write your new code here
19+ function square ( num ) {
20+ return num * num ;
21+ }
1922
2023
You can’t perform that action at this time.
0 commit comments