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

By | April 19, 2017

This program includes Javascript to find the position of the left most vowel in the entered string. 

Input Parameter: A string
Output:
Left-most vowel and the position of the left most vowel in the string

Suggested Read:

 

<pre><? xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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:green" onload = "str_vowel();">
</body>
</html>

 

Input:

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

Output 1: Success case

Output of the left most ovel in the given string using javascript

diagram showing the left most vowel in the given string using javascript

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

diagram showing the left most vowel in the given string using javascript

 

Output 2: When input string has white space

Output of the left most vowel in the given string with space using javascript

Diagram shows the left most vowel in the given string when there is white space

 

Output 3: When there is no vowel present

javascript to find left most vowel in the string output

Diagram shows the output of the javascript when the string does not contain any vowel in it





Author: Ravi Bandakkanavar

A Techie, Blogger, Web Designer, Programmer by passion who aspires to learn new Technologies every day. It has been 6 years since I have been publishing articles and enjoying every bit of it. I want to share knowledge and build a great community with people like you.

Suggested read for you:

Did it help? Comment here..