File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> write your prediction here
2+ // =============> write your prediction here
3+
4+ // I predict that the code will throw an error when trying to call the function capitalise with a string input
5+ // because the variable 'str' is being declared twice within the same scope, which is not allowed in JavaScript.
36
47// call the function capitalise with a string input
58// interpret the error message and figure out why an error is occurring
@@ -10,4 +13,14 @@ function capitalise(str) {
1013}
1114
1215// =============> write your explanation here
16+
17+ // The code will throw a SyntaxError because the variable 'str' is being declared twice within the same scope.
1318// =============> write your new code here
19+
20+ function capitalise ( str ) {
21+ str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
22+ return str ;
23+ }
24+
25+ // Example:
26+ console . log ( capitalise ( "hello" ) ) ; // Output: "Hello"
You can’t perform that action at this time.
0 commit comments