Title Case a Sentence - read-only error


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?


function titleCase(str) {
for (var i = 0; i < str.length; i++) {
 var n = i - 1;
 if (str[n] === " "){
 str[i] = str[i].toUpperCase();   
   str[i] = str[i].toLowerCase()
  return str;

titleCase("I'm a little tea pot");

Link to the challenge:

Strings are immutable, you can’t modify them in-place. This:

str[i] = str[i].toLowerCase()

You can’t do that.