Skip to content

Commit 2c22109

Browse files
authored
detecting and interprating error in 0.js
1 parent d873260 commit 2c22109

File tree

1 file changed

+18
-4
lines changed
  • Sprint-2/1-key-errors

1 file changed

+18
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
4+
// The code will capitalize the first word of the str which gives "Str"
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) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
10-
}
9+
// The error occurs in line 13 and it says "SyntaxError: Identifier 'str' has already been declared"
10+
// The error is informing us that the string str has already been declared in line 12 so we can not declare it again.
11+
12+
//function capitalise(str) {
13+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
14+
// return str;
15+
//}
1116

1217
// =============> write your explanation here
18+
19+
// The code is written to capitalize the first letter of str which is expected to give the result Str.
20+
1321
// =============> write your new code here
22+
23+
function capitalise(str) {
24+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
25+
return str;
26+
}
27+
console.log(capitalise("str"))

0 commit comments

Comments
 (0)