Tell us what’s happening:
Challenge: Intermediate Algorithm Scripting: Pig Latin
I have tested all the testing words. The outcome are identical as they are supposed to be. But the system wouldn’t let me pass. Is there some latent mistake? Please help! Thank you soooo much!
[challenge description:
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.]
Your code so far
function translatePigLatin(str) {
let regex=/[aeiou]/;
let a=str.match(regex);
console.log("firstVowelIsLetter "+a);
let n=str.indexOf(a);
console.log("indexOfVowelIs n= "+n);
let x=str.substr(n);
console.log("firstVowelAndFollowings x= "+x);
console.log();
if (n===0){console.log(str+="way"); return str+="way";}
else if (n===-1){console.log(str+="ay"); return str+="ay";}
else console.log(x+=str.substr(0,n)+"ay"); return x+=str.substr(0,n)+"ay";
}
translatePigLatin("california");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
.