Pig Latin doubt

Hello everyone. Can you find what’s wrong in my code here? The output is:

console.log(translatePigLatin(“paragraphs”))
// aragraphsp,pay


function translatePigLatin(str) {

let consonantRegex = /(^[^aeiou]+)/
let myConsonants = str.match(consonantRegex)

if (consonantRegex.test(str)) {
  
  return str.replace(consonantRegex, '').concat(myConsonants, 'ay')
  
}
else {
  str += 'way'
  return str
}


}

console.log(translatePigLatin("paragraphs"));

Challenge: Pig Latin

Link to the challenge:

.concat() returns an array. That’s why you are seeing a comma when you print the returned value.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.