Tell us what’s happening:
I think I pretty close to solving this one. The loop does iterate through the string I split into an array, but the if
statement’s condition doesn’t catch any other consonants it encounters except for the first one. I also can’t get this to work for strings that don’t have any vowels. I’ve spent the last 2 days trying a number of methods to get this working.
Your code so far
function translatePigLatin(str) {
let testStr = str.split("");
let testRegex = /^[aeiou]/i;
if (testRegex.test(str)) {
return str.concat("way");
} else if (!testRegex.test(str)) {
for (let i = 0; i < testStr.length; i++) {
if (testStr !== testRegex) {
testStr.push(testStr.shift());
return testStr.join("").concat("ay");
}
}
}
}
console.log(translatePigLatin("glove"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0
.
Challenge: Pig Latin
Link to the challenge: