Hi people,
First post here but I’d love to get feedback on why this specific code won’t pass. I don’t want to just check working solutions, I want to learn what I’ve done wrong.
var titleCaseArray = [];
function titleCase(str) {
var myArray = str.split(' ');
for (var i = 0; i <myArray.length; i++) {
titleCaseArray.push(myArray[i].charAt(0).toUpperCase()+myArray[i].toLowerCase().slice(1));
}
str = titleCaseArray.join(" ");
return str;
}
titleCase(“sHoRt AnD sToUt”);
I was really keen to make this work without cheating or looking up too many clues, so I just though about it, broke it down into what I wanted to do, then put it together as best I could. I’m guessing my code is a bit eccentric, and there’s probably a much cleaner way, but hey it works perfectly! Why won’t it pass the test?
I’m actually quite proud of myself for making this work. I’ve been finding coding hard and this is one of the first challenges I’ve done without looking too much up or thinking about it for too long. Felt like I was making a breakthrough, so it’s maddening to now be stuck…
Any advice much appreciated.