Consider a pseudo code of this format:
if(condition-1 || condition-2 || condition-3) {
run these statements;
}
I need to determine which of my three conditions turned out true and hence the inner statements ran. I know switch-case is an alternative to do this but yet I wanted to accomplish through an if statement.
You would need either a switch or multiple ifs if you want to identify the specific condition(s) that is true.
2 Likes
function check(x){
let which;
if((which=-1, x==-1) || (which=-2, x==-2) || (which=-3, x==-3)){
return which;
}
}
Would this work for you?
1 Like
@rmdawson71 Check out MDN
Basically, to give you a picture
expression1, expression2
will evaluate both expression, but return only expression2
. Obviously the solution I provided could’ve been written more gracefully, depending on how exactly if
statement is used, but it should picture the idea.
@rmdawson71 I am just comparing the “innerHTML” of a few elements against a specific value. So yeah! its a simple comparison. I am just gonna try both the suggestions I got from you as well as from @KamilCybulski. Hopefully, it works! And, thank a lot for giving time in responding to this.