Pig Latin - Problem with if function

Pig Latin - Problem with if function
0.0 0

#1

Tell us what’s happening:
Hi there,

I am having a bit of trouble with the pig latin problem. I understand the problem but for some reason, my “else-function” gets executed after my “if-function”. The way I understand it is that if the criteria is met, it should execute my “if-function” and if not, it should go to my “else-function”?

Your code so far

function translatePigLatin(str) {
  var vowels = ["a","e", "i", "o", "u"];
  
  for (i = 0; i<vowels.length; i++){
 if (str.charAt(0) === vowels[i]){
   str += "way";
 } 
  else{
  var first = str.charAt(0);
  return str.substr(1,str.length) + first;
  } 
  }
}

translatePigLatin("are");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36.

Link to the challenge:


#2

That’s not the case (if-else are indeed exclusive), what an odd assessment! But you don’t have to believe me. You can always put a bunch of console.log() calls in to see what is going on.

You’re also not returning anything from the if-true case.