Skip to content

Commit 150a780

Browse files
committed
In 1 key-errors, made a preditions, explained the syntax error, and fixed the conflict with a new variable name
1 parent 9d43b8b commit 150a780

File tree

1 file changed

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

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// I guess the function is trying to capitalise the first letter of the string,
4+
// capture the rest of the string from index 1 to the end of the string,
5+
// and concatenate them together to return the capitalised string
36

47
// call the function capitalise with a string input
58
// interpret the error message and figure out why an error is occurring
6-
9+
/*
710
function capitalise(str) {
811
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
912
return str;
1013
}
14+
*/
1115

1216
// =============> write your explanation here
17+
// After calling the function capitalise with a string input,
18+
// I got a syntax error that "str" has already been declared.
19+
// This is because str has already been declared as a parameter of the function,
20+
// when a new variable named str, it causes a conflict.
21+
1322
// =============> write your new code here
23+
// I renamed the new variable to capitalisedStr to avoid the conflict
24+
25+
function capitalise(str) {
26+
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
27+
return capitalisedStr;
28+
}
29+
console.log(capitalise("hello")); // should return "Hello"

0 commit comments

Comments
 (0)