Tell us what’s happening:
what do i need to do for the the code to also handle words without vowels?
Your code so far
function translatePigLatin(str) {
let pigLatin = '';
let regex = /[aeiou]/gi;
if (str[0].match(regex)) {
pigLatin = str + 'way';
}
else if(str.match(regex) === null) {
pigLatin = str = 'ay';
}
else{
let vowelIndice = str.indexOf(str.match(regex)[0]);
pigLatin = str.substr(vowelIndice) + str.substr(0, vowelIndice) + 'ay';
}
return pigLatin;
}
translatePigLatin("consonant");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3223.0 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin