I am doing Case a sentence but my answer is not being accepted

Tell us what’s happening:
I just cannot figure out the problem in my code and I have tried checking my code but I cannot figure out. So anyone who is willing to tell me the problem.

   **Your code so far**

function titleCase(str) {
let varAble = [];
let stringNew = "";

str.toLowerCase().split(" ").forEach(function nn (str){
varAble.push(str[0].toUpperCase() + str.slice(1));
});

 for(let i = 0; i < varAble.length; i++){
 stringNew = stringNew + " " + varAble[i];    
 }
return stringNew;
}

titleCase("I'm a little tea pot");
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");
titleCase("sHoRt AnD sToUt")
   **Your browser information:**

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

Challenge: Title Case a Sentence

Link to the challenge:

Hi @Abhimanyu2605 !

You should add these console.log statements just before the return so you can compare the correct answer with your answer.

//correct output
 console.log('I\'m A Little Tea Pot')

 //this is your output
 console.log(stringNew)

You should see an extra space with your answer which is why you are failing the tests.

Luckily, there is a helpful string method that will remove whitespace from both ends of a string.
Add that string method to the return statement and the test will pass.

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