Various questions on Pig Latin challenge

in this code

function translatePigLatin(str) {
  var arr = str.split('')
  console.log(arr) // [ 'c', 'o', 'n', 's', 'o', 'n', 'a', 'n', 't' ]
  var cons = []
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] !== 'a' || 'e' || 'i' || 'o' || 'u') {
        arr[i] = 0
    else {
  console.log(cons) // [ 'c', 'o', 'n', 's', 'o', 'n', 'a', 'n', 't' ]
  arr.push(cons + 'ay')
  var final = arr.filter(Boolean)

I am trying to say grab all the consonants before the vowel and then break the for loop. It is grabbing the whole words though and I don’t know why

you can’t compare one single thing to many, you need to do each comparison separately

Is there a shorthand way to do that? Or do you have to write it all out?


if (arr[i] !== 'a' || arr[i] !== 'e' || arr[i] !== 'i' || arr[i] !== 'o' || arr[i] !== 'u')

Still doesnt work

if the first one is true, all the expression is true
if you want to say that arr[i] is not a vowel you need to use &&

Also, please, start using the Ask for help button

If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

function translatePigLatin(str) {
  return str
    .replace(/^[aeiou]\w*/, "$&way")
    .replace(/(^[^aeiou]+)(\w*)/, "$2$1ay");

Why do you need the &

Why does this code:

function translatePigLatin(str) {
  let consonantRegex = /^[^aeiou]+/;
  let myConsonants = str.match(consonantRegex);



[ 'c', index: 0, input: 'consonant', groups: undefined ]

And not just [‘c’]

Because you are missing the g flag.