Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript loop and if statement

function LetterCapitalize(str) { 
     var output = ""+str.charAt(0).toUpperCase();
     for(var i=1; i < str.length; i++){
         if(str.charAt(i - 1) == " ") {
             output += str.charAt(i).toUpperCase();
         } else {
             output += str.charAt(i);
         }
     }
    return output;
}
console.log(LetterCapitalize("hello world"))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #loop #statement
ADD COMMENT
Topic
Name
7+2 =