JavaScript - Learn Intermediate Algorithm Scripting : Pig Latin

Tell us what’s happening:
I’ve been able to iterate through and pass tests for words with vowels first or consonants in a word. However, I can’t seem to pass the consonants only “rhythm” test.

Your code so far


function translatePigLatin (str){
   var regex = str.match(/[aeiou]/);
  var firstConst = str.indexOf(regex);
  var anyConst = str.match(/[a-z&&[^aeiou]]/);

if (firstConst > 0 || anyConst == true) {
return str.slice(firstConst || anyConst) + str.slice(0,firstConst || anyConst) + 'ay';
} 
return str + 'way';
}

translatePigLatin("rhythm");

Your browser information:

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

Challenge: Pig Latin

Link to the challenge:

‘rhythm’ is one “consonant cluster” so it should get ‘ay’ added to the end. But for ‘rhythm’ firstConst is -1 and anyConst is null so your code will add ‘way’ to it instead.

Your problem is here: