Javascript or operator not working
Your logic is flawed:
if your variable strExt
was equal to 'wav'
it would not be equal to 'mp3'
, and versa-visa.
Please explain your desired results more clearly.
I think what you're trying to say is something like (neither 'wav'
nor 'mp3'
):
if ( !( strExt == 'wav' || strExt == 'mp3' ) )
which is logically equivalent to (not 'wav'
and not 'mp3'
):
if ( strExt != 'wav' && strExt != 'mp3' ) )
||
says: if any condition is true, It'll return true, without looking at the ones after it.
So true || false
is true, false || true
is true.
In your case, you say "if strExt is not equal to wav and is not equal to mp3, then execute the code". In case that one of them is true, it executes.
I'm thinking that you're looking for the &&
symbol. The logical and
says "I'll return true only if every condition is true" - when it hits a false, it returns false.
What I think your code should look like:
if (strExt!='wav' && strExt!='mp3')