-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0.js
More file actions
21 lines (18 loc) · 1.07 KB
/
Copy path0.js
File metadata and controls
21 lines (18 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Predict and explain first...
// =============> write your prediction here
// I predict that the error will be a SyntaxError because we are trying to declare a variable with the same name as a parameter. In JavaScript, you cannot declare a variable with the same name as a parameter within the same function scope. This will cause a SyntaxError because it creates a conflict in variable naming.
// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
// =============> write your explanation here
// The original error happened because we tried to declare a new variable
// named `str` with `let` even though `str` was already a parameter. That's
// illegal in JavaScript and produces a SyntaxError. By removing the extra
// declaration (or by returning the string directly) the function works.
// =============> write your new code here
function capitalise(str) {
return `${str[0].toUpperCase()}${str.slice(1)}`;
}