Skip to content

Commit 07075e1

Browse files
committed
I fixed the error and wrote a new code, it runs perfectly
1 parent 8f3d6cf commit 07075e1

File tree

1 file changed

+10
-5
lines changed
  • Sprint-2/1-key-errors

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
//I think it will give an error because we have `str` twice in line 10 we should only have return without `str`
34

45
// call the function capitalise with a string input
56
// interpret the error message and figure out why an error is occurring
67

7-
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
10-
}
8+
119

1210
// =============> write your explanation here
13-
// =============> write your new code here
11+
// The error happened because 'str' was declared twice: once as a parameter and once with 'let' inside the function.
12+
// Also, when calling the function, using a word without quotes caused a ReferenceError.
13+
// After removing the duplicate declaration and passing a string with quotes, the function works correctly,
14+
// =============> write your new code here
15+
function capitalise(str) {
16+
return `${str[0].toUpperCase()}${str.slice(1)}`;
17+
}
18+
console.log(capitalise("Hard"));

0 commit comments

Comments
 (0)