JavaScript to find the position of the left most vowel in string

By | September 21, 2014

This post contains An HTML code to find the position of the left most vowel in a given string using javascript.

Parameter: A string
Output: The position in the string of the left-most vowel

<? xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> string.html </title>
<--script type ="text/javascript">
function str_vowel()
{
var str=prompt("Enter the string\n", " ");
for(var i = 0; i<str.length; i++)
{
if (str.charAt(i) =='a' || str.charAt(i) == 'e' || str.charAt(i) =='i'
|| str.charAt(i) == 'o' || str.charAt(i) == 'u' || str.charAt(i) == 'A' ||
str.charAt(i) == 'E' || str.charAt(i) =='I' || str.charAt(i) =='O' || str.charAt(i) == 'U')
{
document.write("The entered string is:" +str+ "<br/>");
document.write("The leftmost vowel is :"+str.charAt(i)+"<br/>");
var pos = i+1;
document.write("The position of the leftmost vowel " +str.charAt(i)+ " is:" +pos+"\n");
exit;
}
}
document.write("The entered string is:" +str+ "<br/>");
document.write("The entered string has no vowels");
}
<--/script>
</head>
<body style="background-color :yellow" on-Load = "str_vowel ();">//on-Load should be onload
<--style = "text-align">
Program includes Javascript script funcitons to find the position of the left-most vowel in the entered- string. 
<--/script>
</body>
</html>
[/code]

 

 

Please Share: Tweet about this on TwitterShare on FacebookShare on Google+Share on RedditPin on PinterestShare on LinkedInDigg thisShare on StumbleUponShare on TumblrBuffer this pageShare on VKEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *