Slip 17 - A) Write a java script code to accept a string from user and display the occurrences of every vowel character from string

Solution:


<HTML><body>
<script>
function find()
30
{
var vowels = 0;
var consonant = 0;
var specialChar = 0;
var digit = 0;
var str=frm.txt1.value;
var n = str.length;
var i;
for (i = 0; i < n; i++)
{
var ch = str[i];
if ( (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') )
{
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
vowels++;
else
consonant++;
}
else if (ch >= '0' && ch <= '9')
digit++;
else
specialChar++;
}
alert( "Vowels: " + vowels + "Consonant:" + consonant +"Digit:" + digit +"Special Character:" + specialChar ) ;
}
</script>
<form name="frm">
Enter a String:<input name="txt1" type="text" />
<input name="b1" onclick="find();" type="button" value="display" /></form>
</BODY>
</HTML>

Post a Comment

0 Comments