File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
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
3+ // I predict the code will throw an error because the variable `str` is being declared twice in the same function scope.
4+
35
46// call the function capitalise with a string input
57// interpret the error message and figure out why an error is occurring
@@ -10,4 +12,16 @@ function capitalise(str) {
1012}
1113
1214// =============> write your explanation here
15+ // The function already receives `str` as a parameter.
16+ // Inside the function, it tries to declare `let str = ...`,
17+ // which causes a conflict because JavaScript does not
18+ // allow redeclaring the same variable name in the same scope using `let`.
19+ // This leads to a `SyntaxError: Identifier 'str' has already been declared`.
20+
21+
1322// =============> write your new code here
23+ // =============> write your new code here
24+ function capitalise ( str ) {
25+ let capitalisedStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
26+ return capitalisedStr ;
27+ }
You can’t perform that action at this time.
0 commit comments