Tell us what’s happening:
hello it seems im having trouble getting the last if statement right in order to pass the ‘Should handle words where the first vowel comes in the end of the word.’. Is something wrong with my code, because it doesnt clarify what must be returned in this case.
Thanx in advance
Your code so far
function translatePigLatin(str) {
var regexx = /a|i|o|e|u/g;
var aa = str.split('');
var bb = str.slice();
var n = str.length;
if (str[0].match(regexx)) {
return str.concat('way');
}
if (str.match(regexx) == null) {
return str.concat('ay');
}
if (str[0].match(regexx) == null && str[1].match(regexx)) {
aa.shift();
aa.push(bb[0]);
let k = aa.join('');
return k.concat('ay');
}
if (str[0].match(regexx) == null && str[1].match(regexx) == null) {
aa.shift();
aa.shift();
aa.push(bb[0]);
aa.push(bb[1]);
let k = aa.join('');
return k.concat('ay');
}
let checkk = str.slice(0,n-1);
console.log(checkk);
if (str[n-1].match(regexx) && checkk.match(regexx) == null) {
let rr = str[n-1].concat(checkk);
console.log(rr);
let gg = rr.concat('ay');
console.log(gg);
return gg;
}
}
translatePigLatin("ttko");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin