I'm sure RegEx would make this a snap, but they take me all day to work out so I used a loop and
Code:
if (name[i] == 'a' || name[i] == 'e' || name[i] == 'i' || name[i] == 'o' || name[i] == 'u')
This does lead to some strange results if you remove the vowel from the string. So I ended up substituting for the vowels and then removing the token. It took two loops:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript">
function calculateName(name)
{
var myName = "";
var countConsonants = 0;
var count = name.length;
for (var i = 0; i < count; i++)
{
if (name[i] == 'a' || name[i] == 'e' || name[i] == 'i' || name[i] == 'o' || name[i] == 'u')
{
name = name.replace(name[i], '~');
}
}
for (var i = 0; i < count; i++)
{
name = name.replace('~', '');
}
document.getElementById('here').innerHTML = name;
}
</script>
</head>
<body>
<button onclick="calculateName('BillyJoeBoo')">PUSH</button>
<div id="here"></div>
</body>
</html>