Pig Latin help with or statements

Pig Latin help with or statements
0

#1

Tell us what’s happening:
I just have a question with my or statements in the first if statement. The only test case that passed when I only had the first if statement was ‘algorithm’. this led me to believe that my or statements aren’t working so I hardcoded an else if to handle the case with ‘eight’ and that passed. I could do a long list of else ifs for every vowel maybe even ‘y’ but that seems pretty redundant. is there a way I can get the function to check see if str starts with a vowel?

Your code so far


function translatePigLatin(str) {
  if (str.startsWith('a'||'e'||'i'||'u'||'o')){
    return str + "way";
  } else if (str.startsWith('e')) {
    return str + "way";
  } 
}
translatePigLatin("consonant");

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin


#2

The startsWith method can only take two arguments (1st is the string you are trying to find and the optional 2nd argument is the index you want to start look). If you want to use startsWith with || operator, you would need to need separate startsWith calls,. An example checking for just ‘a’ or ‘e’ is below.

  if (str.startsWith('a') || str.startsWith('e')){

#3

that makes sense, thanks for the help.