Translate the provided string to pig latin.

Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an “ay”.

If a word begins with a vowel you just add “way” to the end.

Input strings are guaranteed to be English words in all lowercase.

Here are some helpful links:

function translatePigLatin(str) {
  var newVal = "";
  var pos;
  for (var i = 0; i < str.length; i++) {
    chr = str.charAt(i);
    if (chr == 'a' || chr == 'e' || chr == 'i' ||
      chr == 'o' || chr == 'u')
      break;

    pos = str.indexOf(chr);
    console.log(str[i] + " position: " + pos);

    newVal += chr;

    //get last index
    // pos = newVal.substring(newVal.length - 1); or this:
    pos = newVal.slice(-1);
  }
  console.log("newVal: " + newVal + " " + pos);
  // for(var j=0; j<pos.length; J++) {
  //   console.log(j);
  // }
// console.log(sk);
  var test = str.slice(newVal.indexOf(pos)+1);
  console.log(test);
  if(pos === undefined) {
    console.log(test+"way");
  } else {
    console.log(test+newVal+"ay");
  }
}

translatePigLatin("california") //should return "aliforniacay".
translatePigLatin("paragraphs") //should return "aragraphspay".
translatePigLatin("glove") //should return "oveglay".
translatePigLatin("algorithm") //should return "algorithmway".
translatePigLatin("eight") //should return "eightway".