Skip to content

Commit c786fbc

Browse files
committed
completion of 1-key-errors
1 parent 124ae45 commit c786fbc

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
3+
// The code will throw an error because the variable 'str' is being redeclared inside the function 'capitalise'. The error message is likely to be a syntax error.
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) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
10-
}
7+
//function capitalise(str) {
8+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
//return str;
10+
//}
1111

1212
// =============> write your explanation here
13+
// The error is occurring because we are trying to declare a variable 'str' inside the function that has the same name as the parameter 'str'.To fix this problem, create an variable with a new name Newstr . So we would change the line to: Newstr = `${str[0].toUpperCase()}${str.slice(1)}`;
1314
// =============> write your new code here
15+
function capitalise(str) {
16+
let Newstr = `${str[0].toUpperCase()}${str.slice(1)}`;
17+
return Newstr;
18+
}
19+
str="hello world";
20+
console.log(capitalise(str));

prep/Sprint1 Internship email.docx

14.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)