Hello everyone. Can someone help me with this exercise? I don’t understand, what is wrong with the code.
Thanks in advance.
- Pig Latin Translation.**
Create a function that takes a string of words and moves the first letter of each word to the end of it, then adds ‘ay’ to the end of the word. This is a basic form of “Pig Latin”.
-
Move the first letter of each word to the end of the word.
-
Add “ay” to the end of the word.
-
Words starting with a vowel (A, E, I, O, U) append “way” to the end instead.
Extra Practice
- Preserve proper capitalization as in the examples below.
Examples:
-
pigLatin(“Cats are great pets.”) ➞ “Atscay areway reatgay etspay.”
-
pigLatin(“Tom got a small piece of pie.”) ➞ “Omtay otgay away allsmay iecepay ofway iepay.”
-
pigLatin(“He told us a very exciting tale.”) ➞ “Ehay oldtay usway away eryvay excitingway aletay.”
const pigLatin=(str)=>{
let strArray= str.split(" ");
strArray.pop();
let resultArray = [];
let vowelsArray=["a","e","i","o","u"]
for(let i=0;i<strArray.length;i++)
if(vowelsArray.includes(strArray[i][0])){
strArray[i].slice(1) + strArray[i][0];
strAway.push("way");
} else {
word += "ay";
}
word = word.toLowerCase();
word = word[0].toUpperCase() + word.slice(1);
resultArray.push(word);
}
return resultArray.join(" ") + ".";
}