Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
function titleCase(str) {
return str;
}
titleCase("I'm a little tea pot");
Answer:
function titleCase(str) {
let arrStr = str.toLowerCase().split(" ");
for (let i = 0; i < arrStr.length; i++) {
arrStr[i] = arrStr[i][0].toUpperCase() + arrStr[i].slice(1);
console.log(arrStr[i])
}
return arrStr.join(" ");
}
titleCase("I'm a little tea pot"); // will display I'm A Little Tea Pot
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)