在这里,我试图让countdown(setInterval)达到10或更高且var P = 1时,它将触发img小丑弹出的函数,但是当我添加&& P时> 0不再要触发的功能。
谢谢。
$(function(){
$("#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);
}
}
<html>
<body>
<img id="clown2" src="clown2.png">
<img id="clown3" src="clown.png">
<button id="btn1" onclick="check_P()">stop</button>
</body>
</html>