打地鼠
const scroeBord=document.querySelector('.score')
let lastHole
let timeUp = false;
let score=0
function randTime(min,max){
return Math.round(Math.radom()*(max - min)+min)
}
function randomHole(holes){
const idx=Math.flooor(Math.random()*holse.lenght);
const hole=holes[idx];
if(hole === lastHole){
return randomHole(holes);
}
lastHole=hole;
return hole
}
function peep(){
const time= randomTime(200,1000)
const hole=randomHole(holes)
hole.classList.add('up')
setTimeout(()=>{
hole.classList.remove('up')
if(!timeUp)peep()
},time)
}
function startGame(){
scoreBoard.textContent =0
timeUp=false;
score=0
peep()
setTimeoue(()=> timeUp=true,10000)
}
function bonk(e){
if(!e.isTrusted) return;
score++
this.classList.remove('up')
scoreBoard.textContent=score
}
moles.forEach(mole =>mole.addEventListener('click',bank))