Skip to content

Commit 9027d5d

Browse files
I prediacted that the error aill cbe because of the double declaration of the str identifier and this what happened when i tested the programe. I suggested to change the let variable name into an new name 'newStr' and this fixed the issue.
1 parent 956c1b0 commit 9027d5d

File tree

1 file changed

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

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
// Predict and explain first...
22
// =============>
3-
3+
I predicte that the error will be that the variable str is already declared in the function.
44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
66

77
function capitalise(str) {
8-
let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return newStr;
8+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
return str;
1010
}
1111

1212

13-
// =============> write your explanation here
13+
// =============> write your explanation here
14+
when I run the program it give an error message that the identifier str has already been declared. this is because the variable str is declared twice in the function capitalise and in the variable let str.
15+
to fix this we can change the variable name of the let str to newStr and this will fix the issue.
1416
// =============> write your new code here
17+
function capitalise(str) {
18+
let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
19+
return newStr;
20+
}

0 commit comments

Comments
 (0)