Pig Latin - solution with for loop

Dear All,

my first post in here :slight_smile: I have solved Pig Latin quiz using for loop, to do that after iteration I have reset the counter and use continue (please see the code below). My question is whether is such a loop handling acceptable?

function translatePigLatin(str) {

  let strArray = str.split('');
  let regex = /[aeiou]/;

  if(regex.test(strArray[0])) {
    return str + 'way';
  } else if(regex.test(str) === false) {
    return str + 'ay';
  } else {
      for(let i = 0; i < strArray.length; i++) {
        if(!regex.test(strArray[i])) {
          let tempLetter = strArray[i];
          i=-1; continue;
        } else {
          return strArray.join('') + 'ay'; }


Thank you in advance for your comments.

I haven’t checked the logic, but if it passes the test, it’s a pass…

As an aside, it never hurts to go back later and do another pass and try to refactor the code to condense it…

And some others will take a section of fCC and do a speedrun through it…

these all work different skills with coding.

1 Like