Build a Title Case Converter - Build a Title Case Converter

Tell us what’s happening:

All of my results in the console are correct but I can’t ace the test.. my code is below

Your code so far

function titleCase (phrase) {
let normPhrase = phrase.toLowerCase()
let newPhrase = normPhrase.split(" ")
let result = ""

for (let firstChar of newPhrase){
result += firstChar[0].toUpperCase()
result += firstChar.slice(1)
result += " "
  }

return result

}


console.log(titleCase("I'm a little tea pot"))  

Your browser information:

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

Challenge Information:

Build a Title Case Converter - Build a Title Case Converter

Try this test case:

console.log("***" + titleCase("I'm a little tea pot") + "***")

Huh? It’s the same result with extra characters added to both ends…

Yes. Please run that line of code and tell me what you see.

Here goes one of the error messages…

"titleCase("I'm a little tea pot") should return the string I'm A Little Tea Pot"

and here is my result in the console

>>>> I'm A Little Tea Pot

You did not run the line of code I gave you. Please run the line of code I gave you. I have a very good reason for writing that line. It will show you something important.

Do you want me to run the test after running that line and post the error message here?

Just run that line of code I gave you and tell me what the output in the console is.

@protusga9 please do not interrupt to just blurt out the solution

***I'm A Little Tea Pot ***

Bingo. Now, does the number and location of spaces in your output exactly match the required output for the tests?

Ahh ok I see it’s a spacing issue

1 Like

Exactly. That little trick of adding "***" (or something like that) makes it easier to spot those sort of ‘invisible’ issues with spaces on the end of the line.

Sorry was just showing him a method to remove the extra space after explaining that it is because of the space. But I get you, my bad.

1 Like