Skip to content

Commit 0ffaae1

Browse files
committed
completed task in 1-key-errors/0.js
1 parent 8f3d6cf commit 0ffaae1

File tree

1 file changed

+20
-4
lines changed
  • Sprint-2/1-key-errors

1 file changed

+20
-4
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// code will throw error as the parameter is being redeclared
4+
// in the function.
35

46
// call the function capitalise with a string input
57
// interpret the error message and figure out why an error is occurring
68

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

1214
// =============> write your explanation here
15+
16+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
17+
// ^
18+
19+
// SyntaxError: Identifier 'str' has already been declared indicates
20+
// str is being redeclared in the function as it was already declared
21+
// as a parameter of the function capitalise.
22+
1323
// =============> write your new code here
24+
function capitalise(str) {
25+
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
26+
return capitalisedStr;
27+
}
28+
29+
capitalise("hello") // 'Hello'

0 commit comments

Comments
 (0)