Tell us what’s happening:
As far as I can tell, I have the regex pattern defined so that it looks at the beginning of the string for any match. However when a string such as algorithm
is passed in, I get an error: TypeError: str.match(...) is null
. Since null
is falsey, I would have thought that the second return statement would have been returned but it’s not. How can I fix this so that any words that start with a vowel return {str} + “way”?
Your code so far
function translatePigLatin(str) {
var match = str.match(/^[^aeiou]+/i)[0];
if (match) {
return str.slice(match.length) + str.slice(0, match.length) + "ay";
}
return str + "way";
}
translatePigLatin("algorithm");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0
.
Challenge: Pig Latin
Link to the challenge: