FreeCodeCamp - Pig Latin - Problem with no vowel

FreeCodeCamp - Pig Latin - Problem with no vowel
0

#1

it have a problem with the last question of this exercice. It doesn’t work
Here is my code with some comments i did to help me for the “glove” exemple:

``````/*
*/

function translatePigLatin( str ) {
let regex = /[aeiouy]/i;
let strL = str.length;
let newStr = str;
let x = 0;

for( let k = 0; k < strL; k++ ) {
//very important, it reboot the variable
let newNewStr = "";
//never go here because 'g' is not a consonant
if( ( regex.test( newStr[x] ) ) && ( k == 0 ) ) {
return newStr+"way";

//if not a vowel
}else if( ( regex.test( newStr[x] ) == false ) ){
// k=0 => 'g' from 'glove'
// k=1 => 'l' from 'loveg'
let letter = newStr[0];

// k=0 => 'loveg'
// k=1 => 'ovegl'
newNewStr += newStr.slice( 1 ) + letter;
// newStr = 'loveg'
// newStr = 'ovegl'
newStr = newNewStr;

// k=0 => false 'l'
// k=1 => true 'o' then
//if statement is usefull to not make one more else if
if( regex.test( newStr[x] ) ) {
// return 'oveglay'
return newStr+"ay";
}
}
}

//no vowel (you ultimatly end up there if no vowel are found because they are return in the code above for any cases except this one)
return str;
};

console.log( translatePigLatin("california") ); //aliforniacay
console.log( translatePigLatin("paragraphs") ); //aragraphspay
console.log( translatePigLatin("glove") ); //oveglay
console.log( translatePigLatin("algorithm") ); //algorithmway
console.log( translatePigLatin("eight") ); //eightway
console.log( translatePigLatin("zzzzzzzzzzz") ); //zzzzzzzzzzz
console.log( translatePigLatin("bcdfghzxwtv") ); //bcdfghzxwtv
``````

Thanks

#2

You will have to change two things:

• Return `str + "ay"` when there are no vowels
• Y is not a vowel (or at least that is what they assume in this challenge)

#3

Thanks you ! I didn’t think about the no vowel world having a “ay” at the end my bad.
And ‘y’ is a vowel, at least in my country xD. This should be explained in the exercice :)))))

#4

Y is not considered to be a vowel in this challenge because the challenge states:

Input strings are guaranteed to be English words in all lowercase.

In English, the only letters considered to be vowels are a, e, i, o, and u.

#5

I think it would be better to just write the vowel accepted in the exercice