File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22// =============> write your prediction here
3+ // I predict the code is for capitalising the first letter of a string.
4+
35
46// call the function capitalise with a string input
57// interpret the error message and figure out why an error is occurring
68
7- function capitalise ( str ) {
9+ // the error is "The symbol "str" has already been declared."
10+
11+ /* function capitalise(str) {
812 let str = `${str[0].toUpperCase()}${str.slice(1)}`;
913 return str;
1014}
11-
15+ */
1216// =============> write your explanation here
17+ // Error occurs because the str was mentioned as a parameter in the definition which is already a variable name in the function body.
18+
1319// =============> write your new code here
20+
21+ function capitalise ( str ) {
22+ let capitalisedStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
23+ return capitalisedStr ;
24+ }
25+
26+ // to call the function :
27+
28+ console . log ( capitalise ( "naber?" ) ) ; // Output: "Naber?"
You can’t perform that action at this time.
0 commit comments