-3

I have an if statement that has 4 elements in it. To trigger the alert, I need the first two elements to return true, and one or more of the remaining two elements to be false,

But I get a parsing error saying: Invalid left-hand side in assignment expression.

Any ideas where I am going wrong?

if (
    checkPieceInColumn('P', 'd', currentPosition) &&
    checkPieceInColumn('P', 'e', currentPosition) &&
    (checkPieceInColumn('p', 'd', currentPosition)=false) ||
      (checkPieceInColumn('p', 'e', currentPosition)=false)
  ) {
    alert('condition triggered');
  }
Jon
  • 501
  • 3
  • 18

1 Answers1

0

That's a basic error since you're not compairing things but assigning. You MUST change the = operator by the == operator.

if (
checkPieceInColumn('P', 'd', currentPosition) &&
checkPieceInColumn('P', 'e', currentPosition) &&
(checkPieceInColumn('p', 'd', currentPosition)==false) ||
  (checkPieceInColumn('p', 'e', currentPosition)==false)
) {
  alert('condition triggered');
}

Or just use the ! operator instead:

if (
checkPieceInColumn('P', 'd', currentPosition) &&
checkPieceInColumn('P', 'e', currentPosition) &&
!checkPieceInColumn('p', 'd', currentPosition) ||
  !checkPieceInColumn('p', 'e', currentPosition)
) {
  alert('condition triggered');
}
Isaac Vega
  • 300
  • 3
  • 6