Tell us what’s happening:
Hi everyone
my code here passes all the tests except for the last verification:
Should handle words without vowels.
even though I have checked words without vowels…
for example: pkkkkkkkm
it returns to console: mpkkkkkkkay
which seems to be ok.
what is the test expecting me to do?
Your code so far
function translatePigLatin(str) {
let aux=[];
let newArr=[];
let newStr="";
//catch the first letter
let first=""
first=str.slice(0,1);
//is it a consonant ?
if( isConso(first) ){
aux=str.split("")
aux.some(function(x,i){
if( !isConso(x) ){
console.log("First vowel: "+x+" at pos: "+i)
//everything after position is copied to new string
newStr+=str.substring(i);
newStr+=newArr.join("")+"ay"
return true
}else {
if(i==aux.length-1){
newArr.unshift(x)
newStr=newArr.join("")+"ay"
}else{
newArr.push(x)
}
return false
}
})
}else{
//vowel enter here, just add way to the end
newStr=str.concat("way");
}
function isConso(letter){
let regCon = RegExp(/[^aeiou]/i);
return regCon.test(letter);
}
console.log(newStr)
return newStr;
}
translatePigLatin("pkkkkkkkm"); // mpkkkkkkkay
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin