Im trying to implement a logic whereby each time I click the button the count alternates between 1 and 0. In the following code the count is always 0 as each time I press the button the function sets the count to 0. Please help me out and thanks in advance
<html>
<head>
<script type="text/javascript">
    function main(){
        var button = document.getElementById('button');
        count = 0;
        if(button.onclick && count == 0){
            alert(count);
            count = 1;
        }
        else if(button.onclick && count == 1){
            alert(count);
            count = 0;
        }
    }
</script>
</head>
<body>
    <button type="button" id="button" onclick="main()">Click Me!</button>
</body>
</html>
 
     
     
     
     
     
     
    