Search code examples
javascriptjquerycountcounter

if count == 0 AND otherCount == 0


I have 2 counters "goFoods" and "count". I want an if statement that checks to see if goFoods have reached 9 AND the count is more than 6, then make the TryAgain div visible. I've tried this, but it isn't working.

function checkTryAgain() {
    if(goFoods == 9; && count >= 6; ){
    $("#TryAgain").css({visibility: 'visible',});
    
}}

Solution

  • It works fine if you remove the semicolons from the if statement:

    let goFoods = 9, count = 6
    
    function checkTryAgain() {
        if(goFoods == 9 && count >= 6){
        $("#TryAgain").css({visibility: 'visible',});
        
    }}
    
    checkTryAgain()
    #TryAgain{
      visibility: hidden;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <div id="TryAgain">Try Again</div>