Skip to content

Commit c85f975

Browse files
committed
complete ex 0.js
1 parent d28242a commit c85f975

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============>// I predict JavaScript will give a SyntaxError because str is declared twice in 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

7-
function capitalise(str) {
7+
/*function capitalise(str) {
88
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
99
return str;
1010
}
11-
12-
// =============> write your explanation here
11+
capitalise("hello");*/
12+
/* =============> The error happens because str is already the function's parameter.
13+
let str tries to use the same name again, so JavaScript gives a SyntaxError.
14+
The function stops before it can run. */
1315
// =============> write your new code here
16+
function capitalise(str) {
17+
const result = `${str[0].toUpperCase()}${str.slice(1)}`;
18+
return result;
19+
}
20+
capitalise("hello");
21+
console.log(capitalise("hello"));

0 commit comments

Comments
 (0)