File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed
Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> write your prediction here
2+ // =============> I think the variable 'str' is repeated twice in string literals.
33
44// call the function capitalise with a string input
55// interpret the error message and figure out why an error is occurring
@@ -9,5 +9,11 @@ function capitalise(str) {
99 return str ;
1010}
1111
12- // =============> write your explanation here
12+ // =============> The error occurs because some parts of the code are not allowed in JS.
13+ // The variable 'str' is already declared in line 7 as a parameter
1314// =============> write your new code here
15+
16+ function capitalise ( str ) {
17+ return `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } `
18+ }
19+ console . log ( capitalise ( "shop" ) ) ;
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+ // =============> variable 'decimalNumber' is repeated already declared as a parameter in line 8
55
66// Try playing computer with the example to work out what is going on
77
@@ -14,7 +14,12 @@ function convertToPercentage(decimalNumber) {
1414
1515console . log ( decimalNumber ) ;
1616
17- // =============> write your explanation here
17+ // =============> Again, the error is a syntax error.
18+ // The variable 'decimal' is already declared as a parameter
1819
1920// Finally, correct the code to fix the problem
2021// =============> write your new code here
22+
23+ function convertToPercentage ( decimalNumber ) {
24+ return `${ decimalNumber * 100 } %`
25+ }
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+ // =============> The error occurs because we have not defined 'num'
77
88function square ( 3 ) {
99 return num * num ;
1010}
1111
12- // =============> write the error message here
12+ // =============> It is a syntaxError: Enexpected number
1313
14- // =============> explain this error message here
14+ // =============> In line 8, the number as a parameter is not expected; instead, a variable is expected.
1515
1616// Finally, correct the code to fix the problem
1717
1818// =============> 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