Pig Latin Helpdesk

Tell us what’s happening:

Can someone tell me why this does not work.
The first part passes but the second fails.

Your code so far

function translatePigLatin(str) {
let vowels = ['a', 'e', 'i', 'o', 'u'];
let newStr = "";

if(vowels.indexOf(vowels[0]) > -1) {
  newStr = str + "way";
  return newStr
} else {
    let firstMatch = str.match(/[aeiou]/g) || 0;
    let vowel = str.indexOf(firstMatch[0]);
    newStr = str.substring(vowel) + str.substring(0, vowel) + "ay";
  return newStr;



Challenge: Pig Latin

Link to the challenge:

I’m still learning, but I think the problem is line 5 (counting blank lines) should be

if(str.indexOf … instead of if(vowels.indexOf


this will always give 0
you are checking what’s the index inside the array vowels of vowels[0]

maybe you wanted to check something else there