Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: What is the opposite of the logical operator `A && B`?

In the following code, what is the opposite of the condition (ran1 <= 63 && ran2 <= 18), which should fit in the else portion of the if statement?

Is it both (ran1 <= 63 || ran2 <= 18) and (! (ran1 <= 63 && ran2 <= 18))?

Logically, I suppose that the opposite of A and B is both A or B and neither A nor B. But I'm not sure how to express the neither A nor B bit in JavaScript.

var ran1 = 1 + Math.floor(Math.random() * 100);
var ran2 = 1 + Math.floor(Math.random() * 100);

if (ran1 <= 63 && ran2 <= 18) {
    // code
} else {
    // code
}
like image 445
pourrait Peut-être Avatar asked Dec 22 '15 07:12

pourrait Peut-être


1 Answers

The mathematical negation of A && B is !A || !B, so in your case, it would be

ran1 > 63 || ran2 > 18 
like image 122
nathanvda Avatar answered Oct 17 '22 00:10

nathanvda