// Turns the vowel characters into random cases. String.prototype.RandomCase = function(){ return( this.replace( new RegExp("([aeiou]{1})", "gi"), // Here, we are passing in a nameless function as the parameter for // the "replace" argument of the String Replace method. It uses the $1 // to refer to the grouping of vowels found in the regular expression. function($1){ // Get a random number. if (Math.random() > .5){ // Lowercase this one. return( $1.toLowerCase() ); } else { // Uppercase this one. return( $1.toUpperCase() ); } } ) ); } // Create a test string with plenty of vowels. var strTest = "Ben Nadel is a Pretty Nice Guy. I really like Kinky Solutions and his Coding Style."; // Alert the random-cased string. alert( strTest.RandomCase() );