11// Predict and explain first...
22// =============> write your prediction here
3+ // I think that there will be a SyntaxError because str is already
4+ // declared as a parameter, and I am trying to re-declare it as
5+ // a variable with let inside the function. This is not allowed in
6+ // Javascript.
37
48// call the function capitalise with a string input
59// interpret the error message and figure out why an error is occurring
610
11+ // function capitalise(str) {
12+ // let str = `${str[0].toUpperCase()}${str.slice(1)}`;
13+ // return str;
14+ // }
15+
16+ // =============> write your explanation here
17+ // You can't use let to declare a variable with the same name
18+ // as a parameter in the same function. The parameter str is
19+ // already declared, so when you try to declare it again with let,
20+ // it causes a SyntaxError. To fix this, you can either remove
21+ // let and just assign a new value to str, or you can use a different
22+ // variable name for the capitalised string.
23+ // =============> write your new code here
724function capitalise ( str ) {
8- let str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
25+ str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
926 return str ;
1027}
1128
12- // =============> write your explanation here
13- // =============> write your new code here
29+ console . log ( capitalise ( "hello" ) ) ;
0 commit comments