Discrepancies between the console log and the test

Hi I’m working with “Title Case a Sentence”. According to the “console.log” everything is OK and the strings are correct, but the test says it is not OK. My code is the following:

   **Your code so far**

function titleCase(str) {
 let newStr="";
const myArr = str.split(" ");

// console.log(myArr);
// console.log(myArr.length)
 for(let i=0;i<myArr.length;i++){
   
   myArr[i]=myArr[i].toLowerCase();
   myArr[i]=myArr[i].replace(myArr[i], myArr[i].charAt(0).toUpperCase())+myArr[i].slice(1);
   newStr+=myArr[i]+" ";
 }
 console.log(myArr);
 console.log(newStr);

 return newStr;
}

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

Thanks in advance

Regards.

   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0

Challenge: Title Case a Sentence

Link to the challenge:

I suspect that this line is causing your trouble.

Try this log statement.

OK. I see. The sentence ends with a space!!

Thanks :slight_smile:

2 Likes

One thing you might consider is that instead of concatenating the string at each step, to wait and do it at the end, with the join method.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.