Hello, I am currently trying to set the first letter to uppercase, but I’m starting to get a bit lost, could someone help me out?
Your code so far
function titleCase(str) {
let strArr = str.split(" ")
let newStr = ""
for(let i = 0; i < strArr.length; i ++) {
newStr += strArr[i][0].toUpperCase()
}
return str;
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Never mind I did puesdocode and figured it out with a bit of searching.
function titleCase(str) {
// First I split the string by white space making it like ["I'm", "a", "little", "tea", "pot"]
// make first letter uppercase
// make a local variable that contains the string, then make a global variable for the new string that I want to return
let strArr = str.split(" ");
let finalStr = []
for(let i = 0; i < strArr.length; i++) {
const lowCase = strArr[i].toLowerCase()
const newStr = lowCase.charAt(0).toUpperCase() + lowCase.slice(1);
finalStr.push(newStr);
}
return finalStr.join(" ");
}
console.log(titleCase("I'm a little tea pot"))