File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22// =============> write your prediction here
3+ //I think it will give an error because we have `str` twice in line 10 we should only have return without `str`
34
45// call the function capitalise with a string input
56// interpret the error message and figure out why an error is occurring
67
7- function capitalise ( str ) {
8- let str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9- return str ;
10- }
8+
119
1210// =============> write your explanation here
13- // =============> write your new code here
11+ // The error happened because 'str' was declared twice: once as a parameter and once with 'let' inside the function.
12+ // Also, when calling the function, using a word without quotes caused a ReferenceError.
13+ // After removing the duplicate declaration and passing a string with quotes, the function works correctly,
14+ // =============> write your new code here
15+ function capitalise ( str ) {
16+ return `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
17+ }
18+ console . log ( capitalise ( "Hard" ) ) ;
You can’t perform that action at this time.
0 commit comments