I am trying to write
if (x !== "One" || x !== "Two" || x !== "Three") {
x = undefined;
}
However, this is not working for me. What is the correct way to get the same result?
It works fine when I only have one condition
if (x !== "One") {
x = undefined;
}
I am trying to write
if (x !== "One" || x !== "Two" || x !== "Three") {
x = undefined;
}
However, this is not working for me. What is the correct way to get the same result?
It works fine when I only have one condition
if (x !== "One") {
x = undefined;
}
var
to something? var
is a keyword?
– scrblnrd3
Commented
Aug 20, 2014 at 19:25
if
statement to run? When it's none of these? P.S. You can't name a variable var
.
– gen_Eric
Commented
Aug 20, 2014 at 19:26
if(!(var == 'One' || var == 'Two'))
, which by DeMorgan's Law is if(var != 'One' && var != 'Two')
. You can also simplify this by using an array if(['One', 'Two'].indexOf(var) === -1)
.
– gen_Eric
Commented
Aug 20, 2014 at 19:28
You wanted an and, not an or. And your variable name can't be var
.
var t = "One";
if (t !== "One" && t !== "Two" && t !== "Three") {
t = undefined;
}
Because the previous or(s) would always evaluate to true
. if the variable was "a" or var was "One" it's not "Two" or "Three".