Code Review -JS PigLatin


Hello I did the Fundamentals JS Part 5 and I am a bit confused whether my solution regarding the JS PigLatin is OK/is heading to a right derection etc :slight_smile:
Any help would be appreciated: link of JS code

function translate(testSentece) {

//eng vowels A, E, I, O, U, and sometimes Y can be considered a vowel.
var newSentence  = testSentece.split('');
var vowels = {A, E, I, O, U, Y}
var consonant = {B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z}

for (i=0;i<=vowels.length;i++){ //Rule 1
   if (newSentence[0]==vowels[i]){

   if (newSentence[0]==consonant[i]){//Rule 2
   	let temp = newSentence.shift() //remove 1st element
   	newSentence.push(temp) //move the 1st element to the end
   	newSentence.push('ay') //add an 'ay' at the end of the word

return newSentence.join()

module.exports = {


Hi @AlexandreLeFou,

What is the purpose of making vowels and consonant an object rather than an array?


THNX for answering :slight_smile:

yep I understand your question and it is a bit silly what I have done as with making it an object i can’t iterate as i did and say to the fith element do this/that(vowels[index]==… etc)

I shall retry and if I am stuck again I will return !

:0 thnx for helping-pointing this out