I have a simple bit of code that checks some conditions, and I want each condition to cause a unique output, but if no conditions are met then to cause another unique output.
Is there any way to create an else that is only triggered if all previous if statements fail? I am aware that the below code carries out the same purpose, but it seems cumbersome and it would be nicer to have a quicker way of checking all of the variables than copy and paste all of them into another if statement.
var boolean1 = true,
boolean2 = true,
boolean3 = false;
if (boolean1) {
alert("boolean1");
}
if (boolean2) {
alert("boolean2");
}
if (boolean3) {
alert("boolean3");
}
/* and so on */
if (!boolean1 && !boolean2 && !boolean3 /* etc */ ) {
alert("none");
}
switchwith adefault. See switch.boolean1is true, it won't check theboolean2case.