Algorithm Scripting: pig latin

Can pass last test.
Why

function translatePigLatin(str){
  let rem = '';
  if(str[0]  == 'a' || str[0] == 'e' || str[0] == 'i' || str[0] == 'o' || str[0] == 'u' )
    return str + 'way';
  else{
    for(let x=0;x<str.length;x++){
      if(str[x] == 'a' || str[x] == 'e' || str[x] == 'i' || str[x] == 'o' || str[x] == 'u'){
       return str.slice(x, ) + rem +'ay';
      }else{
        rem += str[x];
      }  
}
  }
return str;
}

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

They want me to return if there are no vowels and i did return str but the compiler didn’t get it. why?

Make sure to return the string with ‘ay’ at the end.
so for eg.
if you have ‘my’ then it becomes ‘myay’

1 Like

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums