First Latter Capitalize

by Pritesh Patel

JavaScript

function capitalize(str) {
  /* 	let words = [];
  	  for(let word of str.split(' ')){
  	    words.push(word[0].toUpperCase() + word.slice(1));
  	  }
  	  console.log(words.join(' ')); */

  let words = str[0].toUpperCase();
  for (let i = 1; i < str.length; i++) {
    if (str[i - 1]==" "){
    	console.log(words+=str[i].toUpperCase());
    }else{
    	words += str[i];
    }
  }
  console.log(words);
}
capitalize("hi there!");