Ex No: 3 COUNT VOWELS
Aim: To write a JavaScript code to count number of vowels in a string.
Algorithm
Step1: Create a folder “Ex3” to place the HTML files.
Step2: Create HTML file “index.html”.
Step3: Add JavaScript code to get the value of text input.
Step4: Use javascript for loop and switch statement to count vowels in the string.
Step5: Using JavaScript display the result in a label.
Source Code

index.html


<!DOCTYPE html>
<html>
  <head>
    <title>Vowel</title>	
    <style>
      header {
        text-align:center;
        height: 100px;
        background-color: linen;
        padding: 10px;
        border-radius: 10px 10px 0px 0px;
      }
      footer {
        text-align:center;
        font-size: 12px;
        height: 50px;
        line-height: 50px;
        background-color: linen;
        padding: 10px;
        border-radius: 10px;
      }
      article{
        width: auto;
        padding: 10px;
        margin:5px;
        overflow-x: auto;
      }
    </style>
    <script type="text/javascript">
    function vowel()
    {
      let i,count;
      count = 0;
      let txt = document.getElementById('txt').value;
      txt = txt.toLowerCase();
      for(i=0;i<txt.length;i++)
      {
        switch(txt[i])
        {
          case 'a':
          case 'e':
          case 'i':
          case 'o':
          case 'u':
                count++;
                break;				
        }//End of Switch
      }//end of for
      document.getElementById('res').innerHTML = count;  
    }
    </script>
  </head>
  <body>		
    <header>
        <h1>Count Vowels</h1>
    </header>	
    <hr>
    <table>
      <tr>
        <td>Enter String:</td>
        <td><input type="text" id="txt" name="txt"></td>
      </tr>
      <tr>
        <td>Vowels Count:</td>
        <td><label id="res"> </label></td>
      </tr>
      <tr>
        <td colspan="2"><input type="button" value="Count" onclick="vowel()"></td>
      </tr>
    </table>
    <footer>
        Developed by K Anbarasan
    </footer>
  </body>
</html>
Result: Thus JavaScript code is written to count number of vowels in a string and display the result.