File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> write your prediction here
2+ // The code has a function that is supposed to capitalise the string passed to it. (only the first letter)
3+ // the string will be stored in the variable str and the function will return its value.
4+ // it takes the first letter (str[0]) and uses toUpperCase() method to capitalise it.
5+ // the str.slice(1) method is used to show the letter.
6+ //
37
48// call the function capitalise with a string input
59// interpret the error message and figure out why an error is occurring
@@ -10,4 +14,14 @@ function capitalise(str) {
1014}
1115
1216// =============> write your explanation here
17+ // an error occured because the variable str was already declared as a parameter of the function so
18+ // there was no need to use let again.
19+
20+
1321// =============> write your new code here
22+ function capitalise ( str ) {
23+ str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
24+ return str ;
25+ }
26+
27+ console . log ( capitalise ( "hello" ) ) ;
You can’t perform that action at this time.
0 commit comments