Tell us what’s happening:
I am working on this challenge using Repl.it as a compiler. According to the tests i’ve made, my function is returning all the expected outputs. However, FCC doesnt recognise my code as valid, because it fails the tests where the word starts in a consonant.
Can you please help me identify where am I going wrong?
Your code so far
function translatePigLatin(str) {
let vowel = ['a','e','i','o','u'];
let strArr = str.split('');
let firstVowelIndex = strArr.findIndex(ele => {return vowel.includes(ele)})
if (vowel.includes(strArr[0]) == true) {
strArr.push('way');
str = strArr.join('');
} else if (vowel.includes(strArr[0]) == false && firstVowelIndex !== -1){
let firstCons = [];
for (let i = 0; i < firstVowelIndex; i++){
firstCons.push(strArr[i]);
}
slicedArr = strArr.slice(firstVowelIndex);
finalArr = slicedArr.concat(firstCons)
str = finalArr.join('') + 'ay';
} else {return str + 'ay'}
return str;
}
Also, if you could evaluate my code and point out the improvements I can make i would really apreciate any criticisms.
Thank you very much,
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
.
Challenge: Pig Latin
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin