My code looks correct but I keep failing

Tell us what’s happening:
For some reason I can’t get this question right but I swear my code is correct. I don’t know what I am missing.

Your code so far


function titleCase(str) {
 var returnStr = ''
let a = str.split(' ')
for (let i = 0 ; i < a.length; i++){
  let b = a[i].toLowerCase()
  let c = b[0].toUpperCase()
  let d = b.slice(1)
  let e = c+d
  var returnStr = returnStr + ' ' + e
}
//  console.log(returnStr)
return returnStr
}

titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");
titleCase("sHoRt AnD sToUt");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Title Case a Sentence

Link to the challenge:

1 Like

Maybe cause it returns a space on the first position:

titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");
' Here Is My Handle Here Is My Spout'

By the way, very nice idea!

1 Like