Title Case a Sentence - Work but doesn't pass

Tell us what’s happening:
Hi everyone,

I did try to solve the Title Case problem and my solution seems to work however the website doesn’t consider me as successful and doesn’t allow me to pass on the next challenge.

Could you review my code and enlight me with guidance,

Thank you,

Xavier

Your code so far

function titleCase(str) {
  var arr = str.toLowerCase().split(" ");
  var updatedWord;
  var newPhrase = "";
  
  function upperCase(letter){
    return letter.toUpperCase();
  }
  
  for (i = 0; i < arr.length; i++){
    updatedWord = arr[i].replace(arr[i][0],upperCase(arr[i][0]));
    newPhrase += updatedWord+" ";
  }
  
  return newPhrase;
}

titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36.

Link to the challenge:

When I test your code with the example you put in your code, I get see the following result:

'Here Is My Handle Here Is My Spout '

That extra space at the end of Spout is why this particular test is failing. You need to figure out how to not have the space at the end. The following is putting the space at the end:

newPhrase += updatedWord+" ";

Thank you Dawson, I am going to have a look at that :+1: