-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyScript.js
More file actions
53 lines (52 loc) · 1.23 KB
/
myScript.js
File metadata and controls
53 lines (52 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const holes=document.querySelectorAll('.hole');
const scoreBoard = document.querySelector('.score');
const moles=document.querySelectorAll('.mole');
let lastHole;
let timeUp=false;
let score=0;
function randomTime (min, max)
{
return Math.round(Math.random()*(max-min)+min);
}
function randomHole(holes)
{
const index=Math.floor(Math.random()*holes.length);
const hole=holes [index];
if(hole ===lastHole)
{
//console.log('Thats the same number');
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==false)
{
peep();
}},time
);
}
function startGame()
{
scoreBoard.textContent=0;
timeUp=false;
score=0;
peep();
setTimeout(()=>{timeUp=true; alert("Time Up");},20000);//10 sec
}
function wack(e)
{
if(!e.isTrusted)
return;
score++;
scoreBoard.textContent=score;
history.parentNode.classList.remove('up');
}
moles.forEach(mole=>mole.addEventListener('click',wack));