File tree Expand file tree Collapse file tree 2 files changed +57901
-5
lines changed
Expand file tree Collapse file tree 2 files changed +57901
-5
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> write your prediction here
2+ // =============> the code gives an error because there is a variable declaration with the same name as the parameter of the function.
33
44// call the function capitalise with a string input
55// interpret the error message and figure out why an error is occurring
66
77function capitalise ( str ) {
8- let str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9- return str ;
8+ let newStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9+ return newStr ;
1010}
1111
12- // =============> write your explanation here
13- // =============> write your new code here
12+
13+ // =============> write your explanation here: The error is occurring because the variable newStr is declared inside the function capitalise,
14+ // but it is being accessed outside the function.
15+
16+ // =============> write your new code here:
17+ // function capitalise(str) {
18+ // let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
19+ // return newStr;
20+ // }
21+ // let newStr = capitalise("hello");
22+ // console.log(newStr);
You can’t perform that action at this time.
0 commit comments