My application requirement is if a single word has a vowel like "anupam" then after its last vowel add "xy". So its result should be "anupxy". But if two vowel continue with in a word then it should be like :
      Oa = Oaxy
    and au = auxy
Gardenhire = Gardxy
Parker = Parkxy
Arney = Arnxy
There are 4 rules.
1. The name cuts off at the second vowel and is replaced by 'xy.'
2. connected vowels count as a single and should stay together.
3. EXCEPTION: when the last letter is 'x' another 'x' is not added.
4. Names with only two connected vowels should have "xy" added to the end
I don't know where is my mistake, My code is :
function doit(userName) {
        var temp = userName.toLowerCase();
        var vowels = "aeiouy"
        var count = 0;
        if(userName) {
            for(var i=0; i<temp.length; i++) {
                if( vowels.indexOf(temp.charAt(i)) > -1 ) {
                    count++;
                    if(count==1) {
                        while( vowels.indexOf(temp.charAt(++i)) != -1 );
                        i--;
                    } else
                        break;
                }
            }
            userName = userName.substr(0, i);
            if( userName.charAt(userName.length-1) == 's' )
                userName += "y";
            else
                userName += "sy";
        } else
            userName = 'Take a lap, Dummy';
        return userName.toUpperCase();
    }