let str = 'JavaScript is my first language'; let str2 = ''; for(let i = 0; i < str.length; i++) { str2 += (!i || str[i - 1] === ' ') ? str[i].toUpperCase() : str[i]; } console.log(str2);