Skip to content

Commit f6d89d1

Browse files
committed
0.js error fixed
1 parent e57d878 commit f6d89d1

File tree

1 file changed

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

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// I predict the code is for capitalising the first letter of a string.
4+
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) {
9+
// the error is "The symbol "str" has already been declared."
10+
11+
/* function capitalise(str) {
812
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
913
return str;
1014
}
11-
15+
*/
1216
// =============> write your explanation here
17+
// Error occurs because the str was mentioned as a parameter in the definition which is already a variable name in the function body.
18+
1319
// =============> write your new code here
20+
21+
function capitalise(str) {
22+
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
23+
return capitalisedStr;
24+
}
25+
26+
// to call the function :
27+
28+
console.log(capitalise("naber?")); // Output: "Naber?"

0 commit comments

Comments
 (0)