Tell us what’s happening:
Your code so far
function translatePigLatin(str) {
let vowel = ['a','e','i','o','u'];
let a = str.split('');
if(vowel.includes(a[0])){
return a.join('')+'way';
}
while(!vowel.includes(a[0])){
a.push(a.splice(0,1));
}
return a.join('') + 'ay';
}
function translatePigLatin(str) {
let vowel = ['a','e','i','o','u'];
let a = str.split('');
if(vowel.includes(a[0])){
return a.join('')+'way';
}
while(true){
if(!vowel.includes(a[0])){
a.push(a.splice(0,1));
}
else {
break;
}
}
return a.join('') + 'ay';
}
translatePigLatin("cc");
function translatePigLatin(str) {
let firstVowel = str.match(/[aeiou]/);
let indexFirstVowel = str.indexOf(firstVowel);
if(indexFirstVowel === 0){
return str + 'way';
}else if(indexFirstVowel > 0){
return str.slice(indexFirstVowel) + str.slice(0,indexFirstVowel) + 'ay';
}
}
translatePigLatin("cccccccccccc");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin