0

in Javascript, how can I express that if array1[i] and array2[j] also equal to either "0", "O" or "Q", then array1[i] is equal to array2[j]? I have tried multiple ways but it didn't work. Thanks.

if ((array1[i] == "0" || "O" || "Q") && (array2[j] == "0" || "O" || "Q")){
          array1[i] == array2[j];
}

or

if ((array1[i] && array2[j]) == "0" || "O" || "Q"){
              array1[i] == array2[j];
}
Jeff Lung
  • 3
  • 2
  • 1
    your first code is correct but change array1[i] == array2[j]; to array1[i] = array2[j]; with single equal sign. double equal and triple equal signs are for compression. single equal sign is for assignment like assigning value in array to array 1 – Andam Jul 17 '22 at 09:07

1 Answers1

1

You can use another array to check whether it includes value of array[i]

const oArr = ["0", "O", "Q"]
if (oArr.includes(array1[i]) && oArr.includes(array2[j])) {
  console.log("They both have 0, O or Q")
}
marekvospel
  • 412
  • 4
  • 9