Tell us what’s happening:
Hi everyone,
I’ve been struggling to complete the Pig Latin challenge. My code below seems to do everything it should - I have tested it against all kinds of inputs and compared with one of the examples and they give identical results, but I do keep failing the test “Should handle words without vowels”. Could someone please take a look and see if anything is wrong with my code?
Thanks!
Your code so far
function translatePigLatin(str) {
let consonantRegex = /^[bcdfghjklmnpqrstvwxz]+/
let arr = str.match(consonantRegex);
if (consonantRegex.test(str) === false) {
return str + "way"
}
while (consonantRegex.test(str)) {
str = str.substr(1);
console.log(str)
}
return str + arr[0] + "ay";
}
translatePigLatin("eight");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin/