Sunday, 31 December 2017

Program of Counting Vowels and Consonants in Javascript

Solution:- 

<html>
<head><title>Count vowels and consonants</title>
<script language="Javascript">

function counting()
{
 data=document.f1.txt.value;
 var a=0,e=0,i=0,o=0,u=0;
 var vow=0,cons=0;
for(j=0;j<document.f1.txt.value.length;j++)
{
cal=data.charAt(j);
            switch(cal)
            {
            case 'a':
case 'A': a++;
  break;
                case 'e': 
case 'E': e++;
  break;
                case 'i': 
case 'I': i++;
          break;
                case 'o':
case 'O': o++;
          break;  
                case 'u':
case 'U': u++;
          break; 
                default: cons++;
break;
            }
         }
vow=a+e+i+o+u;
            alert("\n a : "+a+"\n e : "+e+"\n i : "+i+"\n o : "+o+"\n u : "+u+"\n total vowels : "+vow+"\n consonants : "+cons);
}
</script>
</head>
<body>
<form name="f1">
<input type="text" name="txt" value="" >
<input type="button" name="btn" value="count" onClick="counting()">
</form>
</body>
</html>

Output:-


No comments:

Post a Comment

Popular Posts

Program of Counting Vowels and Consonants in Javascript

Solution:-  <html> <head><title>Count vowels and consonants</title> <script language="Javascript"...