File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// Predict and explain first...
22// =============> write your prediction here
33
4+ // Prediction: the method toUpperCase return the character at index 0 of str as uppercase.
5+ // slice method will return the characters of str starting at index 1 excluding the first character.
6+ // the template literal combines the converted upper case first character and the rest of the string.
7+
48// call the function capitalise with a string input
59// interpret the error message and figure out why an error is occurring
610
@@ -10,4 +14,12 @@ function capitalise(str) {
1014}
1115
1216// =============> write your explanation here
17+
18+ // Explanation: 1. str declares twice.Hence it gives syntax error.
19+ // Refactor: 2. instead of returning str return can directly send back the template literal expression.
20+
1321// =============> write your new code here
22+
23+ function capitalise ( str ) {
24+ return `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
25+ }
You can’t perform that action at this time.
0 commit comments