Tell us what’s happening:
I’m having trouble iterating through the string until it reaches a vowel. How do you iterate a string until it stops at the first vowel? How do you get all of the first consonant letters before it reaches vowel? I iterate the string by using the for loop, and I use the “if” statement if the first letters are consonant, but I only get the first letter consonant.
Your code so far
function translatePigLatin(str) {
var vowel = /[aeiou]/g;
var cons = /[^aeiou]/g;
console.log(cons.test(str[2]))
var consonants = [];
var index = str.charAt(0);
console.log(str.slice(1, str.length))
for(var i = 0; i < str.length; i++){
console.log(str[i])
if(cons.test(str[i])){
consonants.push(str.charAt(i));
console.log(consonants)
var slice = str.slice(consonants.length, str.length);
return slice + consonants + 'ay'
}
}
}
translatePigLatin("glove");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin/