Intermediate Algorithm Scripting - Pig Latin

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';


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Intermediate Algorithm Scripting - Pig Latin

Link to the challenge:

Try adding console.log in more places, to check at each point, if each variable contains what you expect.

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

what’s worse is when i do

let news = str + matched + ‘ay’;

it does output ‘oveglay’ but the test on the left side of the screen says its wrong HAHAHA

it works when I just do str.replace() to replace the consonants with “” but does anyone know why my code doesn’t work cuz i really think it should

  1. There’s a syntax error in return str+ 'way; which is preventing the strings starting with a vowel from completing.

  2. Check the result for matched.length and you should be on the right track for the consonant tests.