function titleCase(str){
let words = str.split(" ");
let word = [];
let final = [];
for ( let wor of words){
word.push(wor.toLowerCase());
}
for (let i = 0; i < word.length; i++){
const chars = word[i].split('');
const firstLetter = chars[0].toUpperCase();
chars[0] = firstLetter;
const joined = chars.join("");
final.push(joined);
}
const finished = final.join(' ');
console.log(finished);
return finished;
}
titleCase("little tea pot");
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")
titleCase("sHoRt AnD sToUt")
What sort of advice are you looking for? What are you concerned about with this code?
If I messed up somewhere or something, just tell me. I am a beginner afterall.
I just think there is a easier and different way of doing this. So if you know it just tell me.
You would know best if you messed something up - does this code do what you need it to do?
I do think your variable names are a bit confusing, especially this business of having words and word be almost the same thing, but one variable name is plural and the other is not.
I see you are using two loops.
Could you combine them into one?
For cleaner code, declare chars with let instead of const.
See if you can streamline the return statement.
Happy doing