jeudi 15 janvier 2015

What condition is false in a multiple conditions if statement

I'm writing a multiple if statement in Javascript. I've 3 (or more) conditions, and I wanna doSomething() only if all these 3 conditions are true. If only one of these 3 are false, I wanna doSomethingElse(). I think my code it's right, but my problem is on another level. What if I wanna know for which condition my statement is false? E.g.: condition1=true, condition2=true, condition3=false.



if (condition1 && condition2 && condition3) {
doSomething();
} else {
doSomethingElse();
};


I've thought that I can put another if statement in the else part.



if (condition1 && condition2 && condition3) {
doSomething();
} else {
if (condition1 == false) {
doWhatIDoWhenC1isFalse();
};
};


Is this the right way? Is there any other way to do this? Maybe faster way! Thank for your help, and be nice to me, it's my second day on Javascript :)


Aucun commentaire:

Enregistrer un commentaire