Else statement does not work

Your current if and else/if conditions are just testing the truthiness of a random string which will always evaluate to true. Since the first condition evaluates to true, you will always skip the else if condition (even though that will also evaluate to true in this instance).

What you actually seem to want to test is whether or not there are elements that exist that match the strings you have as selector strings. If that’s the case, your simplest fix would be to change your if and else statements to look more like jQuery statements and checking the length of the result.

if ($("div[class="resultInfo resultLose"]").length > 0)

and

else if ($("div[class="resultInfo resultWin"]").length > 0)

Leave a Comment