Tell us what’s happening:
I split the string at ’ ’ and store all the words in in strSplit. The used FORLOOP for capitalizing first letter of every word to capitalize and stored in variable firstLetter. Stored rest of the word in variable restLetter. Then use + to add firstLetter and restLetter and stored this result in newLetter. Now i want to use join to take away “” form each word so that it becomes a one string with every first letter capitalized in each word. but my if i applied join on newLetter it is not working.
Your code so far
function titleCase(str) {
var strSplit = (str.split(' '));
var newLetter = [];
var returnString;
var firstLetter;
var restLetter;
for(i=0; i <= strSplit.length ; i++){
firstLetter = strSplit[i].charAt(0).toUpperCase();
//console.log(firstLetter);
restLetter = strSplit[i].slice(1, str.Split).toLowerCase();
newLetter = firstLetter + restLetter;
newLetter.join(" and ");
}
return newLetter;
}
}
//
titleCase("I'm a little tea pot");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/title-case-a-sentence