Pig Latin: how to terminate the loop in below three conditions if there is no vowel in the word

Pig Latin: how to terminate the loop in below three conditions if there is no vowel in the word
0.0 0

#1

Tell us what’s happening:

Your code so far


function translatePigLatin(str) {
 let vowel = ['a','e','i','o','u'];
 let a = str.split('');
 if(vowel.includes(a[0])){
  return a.join('')+'way';
 }
  
  while(!vowel.includes(a[0])){
      a.push(a.splice(0,1));
  }
return a.join('') + 'ay';
}




function translatePigLatin(str) {
 let vowel = ['a','e','i','o','u'];
 let a = str.split('');
 if(vowel.includes(a[0])){
  return a.join('')+'way';
 }
  
  while(true){
    if(!vowel.includes(a[0])){
      a.push(a.splice(0,1));
    }
    else {
      break;
    }
  }
return a.join('') + 'ay';
}

translatePigLatin("cc");
function translatePigLatin(str) {
let firstVowel = str.match(/[aeiou]/);
 let indexFirstVowel = str.indexOf(firstVowel);
  if(indexFirstVowel === 0){
    return str + 'way';
  }else if(indexFirstVowel > 0){
   return str.slice(indexFirstVowel) + str.slice(0,indexFirstVowel) + 'ay';
  }

}



translatePigLatin("cccccccccccc");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin


#2

You can use break; to terminate a loop but if it is a nested loop or a nested code block you may need to put multiple breaks as you break out of each block.