View Single Post
Old 11-12-2012, 04:38 PM   PM User | #5
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
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>
sunfighter is offline   Reply With Quote