Title Case a Sentence | Where is my fault?

Title Case a Sentence | Where is my fault?
0

#1

Hi guys, Im working on it. Here is my code:

function titleCase(str) {
var temp = str.toLowerCase();
var arr = temp.split(" ");

var res = “”;
for(var i = 0 ; i < arr.length; i++){
var temp2 = arr[i];
var arrTemp = temp2.split("");
var firstLetter = arrTemp.shift();
var temp3 = firstLetter.toUpperCase();
arrTemp.unshift(temp3);
res = res + arrTemp.toString().replace(/,/g,"") + " ";
}
return res;
}

titleCase(“HERE IS MY HANDLE HERE IS MY SPOUT”);

ive tested ervery case, all is good. so why it isnt done ???

SORRY for My Bad English


#2

Isn’t arrTemp an array?
Maybe rejoin them as one word.


#3

You’re adding an extra space to the end.


#4

what are u guys talking about?
My code works perfect, my result in all of case is true, so why i still get wrong…


#5

@icartusacrimea is right – your code will always have a blank space after the last word. You’ll have to slice it off or add code to watch for the last word.