-5

The logic I am trying to express is:

  • if condition_1 AND
  • either condition2 OR condition3 AND
  • condition_4 THEN
  • console.log("THING ONE")
  • OTHERWISE
  • console.log("THING TWO");

edit - figured out original issue was in other code whilst writing, so posting answer Q&A-style

user1063287
  • 10,265
  • 25
  • 122
  • 218
  • 3
    Self-answering is encouraged on SO. But, please make sure it is a question that hasn't been asked before. There are hundreds of questions about using multiple conditions in `if` – adiga Aug 10 '19 at 09:59

1 Answers1

-2

Yes, it looks like you can, if the or condition is in parenthesis, eg:

var logged_in = true;
var author_username = "fred";
var username = "fred";
var is_editor = false;
var is_something = true;


if (logged_in === true && (author_username === username || is_editor === true) && is_something === true) {
  console.log("THING ONE");
} else {
  console.log("THING TWO");
}

See also:

How to specify multiple conditions in an if statement in javascript

Which Logic Operator Takes Precedence

user1063287
  • 10,265
  • 25
  • 122
  • 218