Tell us what’s happening:
Hi everybody,
I’m stuck on the “Pig Latin” exercise, I cannot pass the last 2 tests and I don’t understand why.
1* Should handle words where the first vowel comes in the end of the word.
2* Should handle words without vowels.
I tested the function with words with the vowel in the end of the word and without vowels, it looks ok to me… Am I missing something?
Your code so far
function translatePigLatin(str) {
var cons = "bcdfghljklmnpqrstvz";
var vow = "aeiou";
var c = [];
var i = 0;
var str = str.split("");
if(cons.indexOf(str[0])>=0){
while(cons.indexOf(str[i])>=0){
c.push(str[i]);
i++;
}
return str.slice(i,str.length).join("") + c.join("") + "ay";
}
else{
return str.join("") + "way";
}
}
translatePigLatin("consonant");
Your browser information:
First, rather than returning directly as you have, I might suggest storing the value you’ll return to a variable. This will let you console.log() that variable just before you return that value.
That said, for the purposes of this challenge, ‘y’ is not a vowel. It doesn’t appear to be either vowel or consonant in your strings though. For some reason, you also seem to not like ‘w’ very much, as it is neither a consonant or vowel either…
Thank you @snowmonkey!
I just realized that I didn’t put x in the cons string as well (in Italy they are not part of our alphabet, that’s why I forgot ahah)!
I added them and now woks correctly
Yes I always store the parameter/s in another variable, I don’t know why this time I didn’t
1 Like
Well, and you don’t NEED to, in this case, unless you want to be able to throw them out for debug purposes.
And yeah, the language thing becomes a challenge. Doing great, though. keep it up!
1 Like