Skip to content

Commit cb6e13e

Browse files
predicted the error and generated new code
1 parent 793cbac commit cb6e13e

File tree

2 files changed

+57901
-5
lines changed

2 files changed

+57901
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> the code gives an error because there is a variable declaration with the same name as the parameter of the function.
33

44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
66

77
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
8+
let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
return newStr;
1010
}
1111

12-
// =============> write your explanation here
13-
// =============> write your new code here
12+
13+
// =============> write your explanation here: The error is occurring because the variable newStr is declared inside the function capitalise,
14+
// but it is being accessed outside the function.
15+
16+
// =============> write your new code here:
17+
// function capitalise(str) {
18+
// let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
19+
// return newStr;
20+
// }
21+
// let newStr = capitalise("hello");
22+
// console.log(newStr);

0 commit comments

Comments
 (0)