Tell us what’s happening:
Can someone help me with this qn? My code works for all test cases except for ‘glove’, ‘rhythm’, and ‘schwartz’ and i have no idea why.
Your code so far
function translatePigLatin(str) {
let vowelReg = /^[aeiou]/;
if (str.match(vowelReg)){
return str+'way';
}
let consReg = /^[^aeiou]+/;
let matched = str.match(consReg);
console.log(str.slice(matched.length) + matched + 'ay')
return str.slice(matched.length) + matched + 'ay';
}
translatePigLatin("paragraphs");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Pig Latin
yup i alr did. what confuses me is that for glove, matched is being assigned ‘gl’ as it’s supposed to but the resulting string ends up being ‘loveglay’. When i check the length of matched for the ‘glove’ test case it also reads 1 for some reason