Pig Latin _ without vowels

Tell us what’s happening:
Hi everyone :slight_smile:

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

This isn’t the correct result. Why are you moving the very last consonant to the start of the word?

pkkkkkkkm should return pkkkkkkkmay because pkkkkkkkm will be considered as consonant cluster

1 Like

oh I got it from an online pig latin translator
https://lingojam.com/PigLatinTranslator

maybe the translator is wrong.

They are at least following different rules than the FCC challenge.

1 Like

got it! :slight_smile:thanks!

passsed!

Congratulations! Happy coding.

1 Like