File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> write your prediction here
2+ // =============> write your prediction here => This code will throw a syntax error
3+ // because the parameter str is redeclared as a let variable inside the function, which is not allowed.
4+
5+
36
47// call the function capitalise with a string input
58// interpret the error message and figure out why an error is occurring
@@ -9,5 +12,12 @@ function capitalise(str) {
912 return str ;
1013}
1114
12- // =============> write your explanation here
15+ // =============> write your explanation here => The error occurs because you cannot declare
16+ // a new variable with the same name as a function parameter (str) using let inside the function.
17+ // This causes a "Identifier 'str' has already been declared" error.
18+
19+
1320// =============> write your new code here
21+ function capitalise ( str ) {
22+ return `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
23+ }
You can’t perform that action at this time.
0 commit comments