Hello fellow learners!
I’ve been trying to sort this one out:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin
but I just don’t understand the instructions! I’ve read all the threads on the subject in the forum (and there are a lot on the same topic) but because my code doesn’t look like any other I found, I find it hard to pick up on what I am missing. Here is my code:
function translatePigLatin(str) {
var conVow = /^[b-df-hj-np-tv-z][aeiou]/i
var conCon = /^[b-df-hj-np-tv-z][b-df-hj-np-tv-z]/i
var vowelFirst = /^[aeiou]/i
var vowel = /[aeiou]/i
if(!str.match(vowel)){
return str + "ay";
}else if(str.match(conCon)){
var first_letters = str.slice(0,2)
return str.slice(2)+first_letters + "ay";
}else if(str.match(conVow)){
var first_letter = str.slice(0,1)
return str.slice(1)+first_letter + "ay";
}else{
return str + "way";
}
}
translatePigLatin("consonant");
It passes ALL the tests but: “Should handle words where the first vowel comes in the end of the word.”
Problem is: I don’t even understand what it means !!! ↷( ó╻ò)
If the word starts with a vowel, don’t we just add “way” at the end?
translatePigLatin("algorithm") should return "algorithmway".
I’ve read the Wikipedia on PigLatin and all but I’m still clueless about what is expected of me.
Hum…Any clue on what I’m missing because I’m utterly confused.(・_・ヾ
Thanks