Hello all,
Can someone please guide me in the right direction? I’m assuming that there’s a much better way to solve this challenge but I’m having a hard time seeing why my way of thinking won’t pass the challenge. Or more strangely, when I run the tests for my code, sometimes it passes the challenge and sometimes my code doesn’t pass the “should handle words without vowels” requirement. I am assuming that if a string composed without any vowels is passed into the function, that the function merely repeats the vowel-less string and attaches an “-ay” to the end and so that’s why I ended the code with "return str + “ay”. Thanks for any guidance and hope you’re enjoying your day!
function translatePigLatin(str) {
let strArr = [...str];
if (strArr[0] === "a"||strArr[0] === "e"||strArr[0] === "i"||strArr [0] === "o"||strArr[0] === "u"){
return strArr.join("")+ "way";
}else {
while (strArr[0]!= "a" && strArr[0]!= "e" && strArr[0]!= "i" && strArr[0]!= "o" && strArr[0]!= "u"){
let firstCons = strArr.shift();
strArr.push(firstCons);
}return strArr.join("")+"ay"
}
return str + "ay"
}
translatePigLatin("bcdfg");