View Single Post
Old 11-13-2012, 01:16 AM   PM User | #16
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Yep. Worked fine.

Code:
<html>
<body>
<script type="text/javascript">

function calculateName(name)
{
    return  (name.toUpperCase() + "XXX" ).replace( /[aeiou]/ig, "" ).substring(0,3);
}
function calculateName2(name)
{
   return (name.charAt(0) + (name + "XXX").substring(1).replace(/[aeiou]/ig,"") ).substring(0,3).toUpperCase();
}

function demo( word )
{
    document.write( word + "==>> (1) " + calculateName(word) + ", ==>> (2) " + calculateName2(word) + "<hr/>" );
}

demo("zamboni");
demo("alphabet");
demo("zoo");
demo("oui");
</script>
</body>
</html>
Note: Both functions work for words of at least 1 letter. The second one will fail if given a word with no characters. The first one will produce "XXX".
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 11-13-2012 at 01:18 AM..
Old Pedant is offline   Reply With Quote