**Hello this is my code for this challenge when i test it it working but the interpreter does’nt validate my code **
function titleCase(str) {
let words, capitalizeSentence = '';
words = str.toLowerCase().split(' ')
for (let i = 0 ; i<words.length; i++){
capitalizeSentence += words[i][0].toUpperCase()
capitalizeSentence += words[i].slice(1)
capitalizeSentence += ' '
}
console.log(capitalizeSentence)
return capitalizeSentence;
}
titleCase("I'm a little tea pot");
//titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")
//titleCase("sHoRt AnD sToUt")
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 12499.73.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.113 Safari/537.36.
This is your code, with added console.log statements, check those to figure out what’s wrong.
function titleCase(str) {
console.log(str.length) // 20
let words, capitalizeSentence = '';
words = str.toLowerCase().split(' ')
for (let i = 0; i < words.length; i++) {
capitalizeSentence += words[i][0].toUpperCase()
capitalizeSentence += words[i].slice(1)
capitalizeSentence += ' '
}
console.log(capitalizeSentence.length) // 21
return capitalizeSentence;
}
titleCase("I'm a little tea pot");
//titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")
//titleCase("sHoRt AnD sToUt")
hi thanks you i saw the error , the length of the string i return is greather than the initial string length because i add one more blank space after the last words , thank for the help , i didn’t notice this before .