Skip to content

Commit 0da90b9

Browse files
committed
Solved and explained 0.js in errors
1 parent cd53ceb commit 0da90b9

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

  • Sprint-3/1-key-errors

‎Sprint-3/1-key-errors/0.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
//Answer: I predict that there will be a Reference Error, because str get's re-declared with let
4+
//inside the function even though it already is declared as it is the parameter. Perhaps it would
5+
// be solved by removing the "let".
36

47
// call the function capitalise with a string input
58
// interpret the error message and figure out why an error is occurring
69

10+
/*
711
function capitalise(str) {
812
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
913
return str;
1014
}
1115
16+
console.log(capitalise("hellllo");
17+
*/
18+
1219
// =============> write your explanation here
20+
// Answer: I got a Syntax Error, Identifier 'str' has already been declared. So 'str' needs to not
21+
// be declared again. I will try to write the code without the let
1322
// =============> write your new code here
23+
24+
function capitalise(str) {
25+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
26+
return str;
27+
}
28+
console.log(capitalise("hellllo"));

0 commit comments

Comments
 (0)