Tell us what’s happening: Can someone help me with this code? It’s passing only the first two tests, and my regex and for-loop don’t seem to be working
Your code so far
function translatePigLatin(str) {
var regex = /[aeiou]/;
let arr = str.split('');
let temp = [];
if (arr[0] === regex) {
return arr.join('').concat("way");
} else {
for (let i = 0; i < arr.length; i++){
let count = 0;
if (arr[i] !== regex) {
temp.push(arr[i]);
count++;
} else {
break;
}
let newWord = arr.slice(count).concat(temp);
return newWord.join('').concat("ay");
}
}
}
translatePigLatin("consonant");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.
well at least you have the right idea. You just used the test incorrectly.
Try this
if (regex.test(arr[0])) {
I do suggest after you fix that line, that you do exactly what I’m doing on your behalf, that is, go back and read your code, line by line and ask yourself if each line of code is doing something useful and if so what. Is it really working as you were expecting?
Then if you think your code is really good, then add console.log statements to try to identify further issues.