Hello everybody,
my last test is not passing… I tried to cover it in the middle with my “else if” statement (commented out), but it corrupted the functionning part. Any idea how to fix this?
Here’s my code:
function translatePigLatin(str) {
let vowelRegex = /^[aeiou]+/i;
let noVowelRegex = /[^aeiou]+/i;
if (vowelRegex.test(str)) {
return str + "way";
/* } else if (noVowelRegex.test(str)) {
return str + "ay"; */
} else {
let consRegex = /^[^aeiou]+/i;
let latinStr = str + str.match(consRegex) + "ay";
latinStr = latinStr.replace(consRegex, "");
return latinStr;
}
}
console.log(translatePigLatin("consonant"));
to make it easier to help you, please include challenge link and format your code correctly. You could use the Ask for help button and it would create a post with the challenge link and your code already included, you would then just need to write your question…
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
Please use the “preformatted text” tool in the editor (</>) to add backticks around text.
or also /^[^aeiou]+$/i will work, to check that the string is all made of not-vowel characters. This would return true with the test method if there are no vowels