** Help Needed ** Pig Latin

Here’s the link to the challenge:

Here’s my code:

function translatePigLatin(str) {
  var firstVowel = str.match(/[aeiou]/);
  var firstPosition = str.indexOf(firstVowel);
  if (firstPosition > 0) {
    return str.substring(firstPosition) + str.substring(0, firstPosition) + "ay";
  } else {
    return str + "way";
  }
}

I’m unable to pass the final test case:

“Should handle words without vowels. translatePigLatin("rhythm") should return the string rhythmay.”

Could anyone please advise what I’m doing wrong here?

“rhythm” contains no vowels, so firstPosition is not greater than 0, which means your logic is adding “way” at the end instead of “ay”.