Title Case a Sentence - help

Hi freeCodeCampers!

I’m going through all the challenges on freeCodeCamp and enjoying them a lot, however I’ve met a fierce opponent, the Title Case a Sentence. I’ve been on this challenge for a couple of days and I think I’m close to the solution. Could a kind soul please point me at the mistake I’m making without giving me the solution?

Here’s my code:

function titleCase(str) {

var splittedStr = str.toLowerCase().split(’ ');

for (var i = 0, length = splittedStr.length; i < length; i++) {
var emptyArr = ;

emptyArr.push((splittedStr[i].charAt(0).toUpperCase() + splittedStr[i].slice(1)));

var finalString = emptyArr.join('');


return finalString;


titleCase(“sHoRt AnD sToUt”);

I actually solved it! All I needed to do was moving the empty array declaration outside the for loop =)