title: while loop is not working properly
body: <p>I am writing code for my one of the exercises in freecodecamp.com called as <a href="https://en.wikipedia.org/wiki/Pig_Latin" rel="nofollow noreferrer">Pig Latin</a> problem. For a while loop it  should stop executing the code inside it  when the condition becomes wrong.For  my case the while loop must stop executing the codes inside it when it finds that it seen a vowel in the charas array during iteration. I think my code is correct in my point of view, but while loop is not stopping execution when it sees a vowel instead it iterate through every element in the charas array.</p>
  
  <p>Here is my code </p>
  
  <pre><code>function translatePigLatin(str) {
    var vowels = ['a','e','i','o','u'];
    var f="";
    var charas = str.split("");
    if(vowels.indexOf(charas[0])!==-1) {
        // vowel
      charas.push("w");
      charas.push("a");
      charas.push("y");
      f = charas.join("");
    } else {
      //if first letter  is a consonant or cluster of consonants
      var i = 0;
      while(vowels.indexOf(charas[i]) ===-1) {
       charas.push(charas[i]);
       charas.splice(i,1);
       i = i+1;
       }    
     charas.push('a');
     charas.push('y');
     f  = charas.join("");   
    }
    return f;
  }
  
  translatePigLatin("california");
  </code></pre>