File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22// =============> write your prediction here
3+ // I guess the function is trying to capitalise the first letter of the string,
4+ // capture the rest of the string from index 1 to the end of the string,
5+ // and concatenate them together to return the capitalised string
36
47// call the function capitalise with a string input
58// interpret the error message and figure out why an error is occurring
6-
9+ /*
710function capitalise(str) {
811 let str = `${str[0].toUpperCase()}${str.slice(1)}`;
912 return str;
1013}
14+ */
1115
1216// =============> write your explanation here
17+ // After calling the function capitalise with a string input,
18+ // I got a syntax error that "str" has already been declared.
19+ // This is because str has already been declared as a parameter of the function,
20+ // when a new variable named str, it causes a conflict.
21+
1322// =============> write your new code here
23+ // I renamed the new variable to capitalisedStr to avoid the conflict
24+
25+ function capitalise ( str ) {
26+ let capitalisedStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
27+ return capitalisedStr ;
28+ }
29+ console . log ( capitalise ( "hello" ) ) ; // should return "Hello"
You can’t perform that action at this time.
0 commit comments