Friday, 26 August 2011

Vowels count in javascript


<script language="javascript" type="text/javascript">
    function check()
    {
        var str =document.getElementById("textboxing").value;
        var chr = ""
        var nVowels = 0
        //Counting all the vowels except y.
        for (pos = 0; pos < str.length; pos++)
        {
            chr = str.charAt(pos);
            if (chr == "a" || chr == "e" || chr == "i" || chr == "o" || chr == "u" ||
                chr == "A" || chr == "E" || chr == "I" || chr == "O" || chr == "U")
                nVowels++;
        }
            alert("There were " + nVowels + " vowels.");
    }
    </script>


<input type="text" id="textboxing" />
    <input type="button" onclick="check()" />


i/p :  india  --- o/p : There were 3 vowels
i/p :  bDf   --- 0/p : There were 0 vowels

Tag: vowel count in string in javascript, vowels count in javascript, vowels count in javascript in asp.net

No comments:

Post a Comment

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute                             '{ "@id": 1001, "@name&q...