My code is giving me a string with consonants an ay at the end when I code in Repl.it editor but I cannot pass in FCC. Getting “Should handle words without vowels.”
Can anyone see what I made wrong?
function translatePigLatin(str) {
let newStr = "";
let kons = "";
let r = /[aeoiuy]/;
let res = str.indexOf(str.match(r));
if(res === -1){
newStr = str + "ay";
}
else if(res === 0 ){
newStr = str + "way";
}else {
kons =str.slice(res);
newStr = kons + str.slice(0,res) +"ay"
}
return newStr;
}
translatePigLatin("grp")