Files
JavaScript-from-Beginner-to…/Chapter 08/Exercise_8.4.js
T
2021-11-30 18:21:53 +05:30

13 lines
357 B
JavaScript
Vendored

const val = "thIs will be capiTalized for each word";
function wordsCaps(str) {
str = str.toLowerCase();
const tempArr = [];
let words = str.split(" ");
words.forEach(word => {
let temp = word.slice(0, 1).toUpperCase() + word.slice(1);
tempArr.push(temp);
});
return tempArr.join(" ");
}
console.log(wordsCaps(val));