Intermediate Algorithm Scripting - Search and Replace

Tell us what’s happening:
I am stuck. I tried all solutions from Hints. However, nothing works.

Your code so far

function translatePigLatin(str) {
return str
.replace(/[1]\w*/, “$&way”)
.replace(/([2]+)(\w*)/, “$2$1ay”);
}

// test here
translatePigLatin(“consonant”);

function translatePigLatin(str) {
  return str
    .replace(/^[aeiou]\w*/, "$&way")
    .replace(/(^[^aeiou]+)(\w*)/, "$2$1ay");
}

// test here
translatePigLatin("consonant");

Your browser information:

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

Challenge: Intermediate Algorithm Scripting - Search and Replace

Link to the challenge:


  1. aeiou ↩︎

  2. ^aeiou ↩︎

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