Pig Latin help needed

Pig Latin help needed
0

#1

Tell us what’s happening:
Can someone guide me whats the problem in my code ? I have checked my code with different inputs at developer.mozzila.org with console.log in replace of return and its working fine.
Your code so far

   function translatePigLatin(str) {
  var newName = ""
var check = ["a","e","i","o","u"]
for(let i = 0; i <str.length;i++)
 { 
  if(check.includes(str[i]) == true)
  {
    
    newName = str.slice(i)
    let j = i

    i = str.length - 1
    if (newName.length == str.length)
    {
      newName = newName + "way"
}
      else{
      
newName = newName + str.slice(0,j) +"ay"

    }
  }
    else {
      newName = ""
    }
  }
  
  
   
 
    
return newName
    
  }
translatePigLatin("rhythm");

#2

Make sure to always to surround your for loop code block in { and }. The FCC tests do not work otherwise.

Also, it would really help you identify code blocks, if you properly indented your code. Currently, it is not.


#3

Thanks for your help , last challenge in this current challenge is to accept word with no vowels. My code works fine though. Why it is not accepting?


#4

Your function returns a blank string the word “rhythm” is passed as an argument.


#5

code edited, can you please check it now.


#6

Can you check if there is an error with the challenge ?


#7

Your code still returns a blank string. You can see for yourself by adding console.log(newName) before the return statement and checking your browser’s console (Ctrl+Shft+J in Chrome).

The problem is your else block of code (below). In your for loop you check if each letter is a vowel, if it is not, you assign newName a blank string. Since there are no vowels in “rhythm”, it just keeps assigning a blank string during each iteration, so that when the for loop is complete, newName is a blank string.

} else {
	newName = '';
}

#8

What should it return if the word rhythm is passed, though it is not clear in instructions.


#9

The instructions state:

Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an “ay”.

“rhythm” is just one big consonant cluster, so it moves to the end of the string and then “ay” gets added. The correct return value would be “rhythmay”.


#10

Thanks for your help. Done with the challenge. Was confused in consonant cluster thanks though.