Hello,
I am getting an error “4 is read-only” when running the below code. Can anyone help and advise why i am getting the error?
Thanks
function titleCase(str) {
for (var i = 0; i < str.length; i++) {
var n = i - 1;
if (str[n] === " "){
str[i] = str[i].toUpperCase();
}else{
str[i] = str[i].toLowerCase()
}
}
return str;
}
titleCase("I'm a little tea pot");
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence