Can someone tell me what's wrong with this code? [ Title Case a Sentence ]

Good afternoon everyone,

I had a hard time trying to figure out this challenge. I feel like I got this but I’m not getting the green light for being correct. Please advise on my code below. I don’t want to see what others have, I’d like to learn what the issue is.
Thanks in advance!

p.s. Ignore the basic nomenclature.

Title Case a Sentence

function titleCase(str) {
var lowerCase = str.toLowerCase();
var splitter = lowerCase.split(" ");
var total = “”;
var split2 = “”;
var reverso = “”; //Ignore
var joiner = “”;
for (var i = 0; i < splitter.length; i++) {
total = total + splitter[i].charAt(0).toUpperCase() + splitter[i].slice(1) + " “;
split2 = total.split(” “);
joiner = split2.join(” ");

} return joiner;
}

titleCase(“I’m a little tea pot”);

You’re adding an extra space to the end (i.e. "I’m A Little Tea Pot ").

2 Likes

What she said. Try adding the space in the joiner command.

1 Like

Great thank you both! I used trim()