-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0.js
More file actions
44 lines (34 loc) · 1.48 KB
/
Copy path0.js
File metadata and controls
44 lines (34 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Predict and explain first...
// =============> write your prediction here
// 1.*Answer
// We have declared the "str" twice.It is already declared
// in this function's parameter, hence causing the conflict.
// Although "let" allows re-assignment of variables, the issue is redeclaration,
// not reassignment.
// call the function capitalise with a string input
// 2.*Answer
// It throws an error detailed below;
// / home/justice/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/tempCodeRunnerFile.js:2
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// ^
// SyntaxError: Identifier 'str' has already been declared.
// interpret the error message and figure out why an error is occurring
// 3.*Answer
// The SyntaxError - Something is invalid that is not following
// Javascript rules.
// The identifier - a name used in the code has a problem and it
// lets m know which one in this case "str". It also let's me know
// what the problem is in this case "str" has already been declared.
//Fix this code:
// function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
// }
// =============> write your explanation here
//I have re-assigned the "str" variable and it now runs with no errors.
// I also checked with console.log to see the output.
// =============> write your new code here
function capitalise(str) {
return `${str[0].toUpperCase()}${str.slice(1)}`;
}
console.log(capitalise("justice"));