Skip to content

Commit 472c56d

Browse files
committed
fix the code as requested
1 parent 8c774bc commit 472c56d

File tree

1 file changed

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

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
// Predict and explain first...
2-
// =============> write your prediction here : There will be an error.
2+
// =============> write your prediction here :
3+
// The function capitalise is expected to take a string input and return the string with the first letter capitalised. When called with the input "hello", it should return "Hello". However, since the function body is empty, it will likely result in an error or return undefined.
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;
8+
// function capitalise(str) {
9+
//let str = `${str[0].toUpperCase()}${str.slice(1)}`;
10+
// return str;
11+
//}
1012

11-
// =============> write your explanation here : Because str has been used(declared) twice. As an input(parameter) to the function(capitalise) and with let. We should used a different variable.
13+
// =============> write your explanation here :
14+
// The function capitalise is called with the string "hello" as an argument. The function takes the first character of the string, converts it to uppercase, and concatenates it with the rest of the string starting from the second character. The result is "Hello", which is then returned and logged to the console. There is no error in this code; it works as intended.
1215

1316
// =============> write your new code here :
14-
/*
17+
1518
function capitalise(str) {
16-
let cap = `${str[0].toUpperCase()}${str.slice(1)}`;
17-
return cap;
19+
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
20+
return capitalisedStr;
1821
}
19-
console.log(capitalise("str"));
20-
*/
22+
23+
console.log(capitalise("hello"));

0 commit comments

Comments
 (0)