Skip to content

Commit b383e53

Browse files
committed
0.js
1 parent 5cb7a47 commit b383e53

File tree

1 file changed

+12
-2
lines changed
  • Sprint-2/1-key-errors

1 file changed

+12
-2
lines changed

Sprint-2/1-key-errors/0.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> write your prediction here => This code will throw a syntax error
3+
// because the parameter str is redeclared as a let variable inside the function, which is not allowed.
4+
5+
36

47
// call the function capitalise with a string input
58
// interpret the error message and figure out why an error is occurring
@@ -9,5 +12,12 @@ function capitalise(str) {
912
return str;
1013
}
1114

12-
// =============> write your explanation here
15+
// =============> write your explanation here => The error occurs because you cannot declare
16+
// a new variable with the same name as a function parameter (str) using let inside the function.
17+
// This causes a "Identifier 'str' has already been declared" error.
18+
19+
1320
// =============> write your new code here
21+
function capitalise(str) {
22+
return `${str[0].toUpperCase()}${str.slice(1)}`;
23+
}

0 commit comments

Comments
 (0)