Title Case a Sentence (Help needed)

I am working on this challenge: Basic Algorithm Scripting: Title Case a Sentence
I can see the individual words, but cannot make out where the return value goes wrong.
Thanks in advance!
Brian

function titleCase(str) {
let words = str.toLowerCase().split(’ ‘);
for ( let i=0; i <= words.length; i++ ) {
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
console.log( words[i] );
};
return ( words.join(’ ') );
};

titleCase(“I’m a little tea pot”);

Just solved the problem… the condition should be “<” not “<=”.

Followup question…What are some good methods for trouble-shooting in this interface…I can see “console.log()” work. Any other suggestions?

In the FCC editor, console.log is pretty much it as debugging tools go. There is also a neat code visualizer at pythontutor.com that you can try your algorithms in to get some deeper insights as to how they run. (Despite the name, pythontutor handles more languages than python, including javascript)

1 Like