Title Case a Sentence HELP NEEDED

Title Case a Sentence HELP NEEDED
0

#1

I’ve been working on this for a week on and off, and it keeps telling me that myNewArray.replace is not a function. I thought it was a method, which is a subtype of function maybe? But anyway, the method above it is syntax’d the same and it goes through. Can someone tell me what I’m doing wrong here? Trying to take the sentence, split into an array, lowercase everything at first, then use a for loop that indexes [i][0] to .toUpperCase the first index for each part of the array and then return the result. As a side nite, I probably should turn it into a string before I return the end product, but I haven’t got that far yet. Any and all help will be greatly appreciated!

Your code so far

function titleCase(str) {
  var myNewArray = [];
  
  var myNewString = str.toLowerCase().split(" ");
 
  for (var i =0; i <myNewString.length; i++) {
    myNewArray.push(myNewString[i]);
    myNewArray.replace(myNewString[i][0], myNewString[i][0].toUpperCase);
 
  }
  
  
  return myNewArray;  
  
  
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:54.0) Gecko/20100101 Firefox/54.0.1 Waterfox/54.0.1.

Link to the challenge:


#2

I fixed a dumb error on my part, but unfortunately that isn’t the big problem I’m having.

Here is result (still saying myNewArray.preplace() is not a function.

function titleCase(str) {
  var myNewArray = [];

  var myNewString = str.toLowerCase().split(" ");

  for (var i =0; i <myNewString.length; i++) {
  myNewArray.push(myNewString[i]);
  myNewArray.replace(myNewArray[i][0], myNewArray[i][0].toUpperCase);

 }


return myNewArray;  


}

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

#3

The replace function only works on strings. myNewArray is an array.

You need to apply the replace function to an element of myNewArray which will be a string.