Basic Algorithm Scripting: Title Case a Sentence seems to be glitching (nvm i just messed up)

Tell us what’s happening:
it seems to me that my code is accomplishing the task but it isn’t passing the verification. am i doing something wrong?

Your code so far


function titleCase(str) {
let newStr = '';
let newStrArray = str.split(' ');
for (let i = 0; i < newStrArray.length; i++) {
  let currentWord = newStrArray[i];
  for (let j = 0; j < currentWord.length; j++) {
    let currentLetter = newStrArray[i][j];
    if (j == 0) {
      currentLetter = currentLetter.toUpperCase();
    }
    else {
      currentLetter = currentLetter.toLowerCase();
    }
    newStr += currentLetter;
  }
  newStr += ' ';
}
return newStr;
}

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

Your browser information:

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

Challenge: Title Case a Sentence

Link to the challenge:

I believe that you are adding an extra space at the end of your strings.

3 Likes

ohhh! thanks, that was the problem!