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
}
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
}
Share
Improve this question
asked Dec 22, 2015 at 7:36
pourrait Peut-êtrepourrait Peut-être
2911 gold badge3 silver badges9 bronze badges
2
-
2
ran1 > 63 || ran2 > 18
-- you need to inverse every operand. en.wikipedia/wiki/De_Morgan%27s_laws – zerkms Commented Dec 22, 2015 at 7:38 - 2 Read on De Morgan's laws. – Amadan Commented Dec 22, 2015 at 7:39
1 Answer
Reset to default 15The mathematical negation of A && B
is !A || !B
, so in your case, it would be
ran1 > 63 || ran2 > 18