Title Case a Sentence doesnt work. Please help

Can anyone tell me why this is not working?

Your code so far

function titleCase(str) {
  var output=" ";
  var newWord=true;
  for(var i=0; i<str.length; i++){
    if (newWord){
      newWord = false;
    }else output+=str[i];
    if (str[i]===" "){
      newWord = true;
  console.log(output+" .");
  return output+" .";

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36.

Link to the challenge:

You are almost there. Note that you only have to return the original str in capital case. So you don’t need to add a space at the front and also no space and dot at the end:
'Hello' instead of ' Hello .'

1 Like

Thank you very much.