samedi 7 décembre 2019

When I add && P>0 the functon doesn't want to fire?

Here, I'm trying to have a countdown(setInterval) to when the count is 10 or higher and var P = 1 then it will trigger the function where the img clown will popup.However, when I add the && P>0 The function no-longer wants to trigger.

Thank you.




            $("#clown2").hide(100);

            /*.......HIDES EVERYTHING FROM START OF GAME.....*/

        });

   P = 0;
    function check_P(){
        P= 1;
        var P = 1;
        if (P === 1) {

            console.log("P is now one!");
        }else{
            var P = 0;

            console.log("P is now equal back to zero!");
            console.log(++P);
        }
    }

var count = 0;
var clear = setInterval(counter,1000);  


 function counter(){

    console.log(++count);
    if(count>= 10 && P>0){
    $("#clown2").show(1000);

    }
 }


</script>


<body>
    <img id="clown2" src="clown2.png">
    <img id="clown3" src="clown.png">

<button id="btn1" onclick="check_P()">stop</button>
</body>
</html> ``` 

Aucun commentaire:

Enregistrer un commentaire