DannyBoy DannyBoy - 29 days ago 7
Javascript Question

using if statement with multiple success cases

I am trying to create an if statement that it uses multiple success case. For example if the first branch is success, it has to still check the second branch, maybe that turns success as well.
in the following code, the statement exists once it success in the first branch.
I want it to go trough and check the next one as well.



var branch1 = true;
var branch2 = true;

if(branch1 === true){
console.log("branch1");
}
else if(branch2 === true){
console.log("branch2");
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>





So my ideal respond for the above code would be branch1, and branch2 as well.
I might add more than two branches.. but I simplified it here.
Any idea?

Thanks

Answer Source

Just remove the word "else"

if(branch1 === true){
    console.log("branch1");
}
if(branch2 === true){
    console.log("branch2");
}