-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfastest.js
71 lines (64 loc) · 2.43 KB
/
fastest.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
let gameForm = document.getElementById('game-start-form');
let timeDuration = document.getElementById('duration');
let sCountNumber = document.getElementById("scount");
let lCountNumber = document.getElementById("lcount");
let sCountWin = document.getElementById("scountWinner");
let lCountWin = document.getElementById("lcountWinner");
let restartButton = document.getElementById("restart");
let sCount = 0;
let lCount = 0;
document.addEventListener("keydown", keyCount);
function keyCount(event)
{
if (timeDuration.value > 0) {
if(event.code === "KeyL"){
lCount++;
lCountNumber.innerHTML = lCount;
lCountWin.innerHTML = "";
sCountWin.innerHTML = "";
}
if(event.code === "KeyS"){
sCount++;
sCountNumber.innerHTML = sCount;
lCountWin.innerHTML = "";
sCountWin.innerHTML = "";
}
}
}
gameForm.addEventListener("click",(event)=>{
if (timeDuration.value > 0) {
let secs = 0;
let id = setInterval(function() {
secs++;
console.log(secs);
if (secs >= 1){
if (sCount === 0 && lCount === 0){
sCountWin.innerHTML = "Game start please press S";
lCountWin.innerHTML = "Game start please press L";
}
}
if(secs == timeDuration.value){
clearInterval(id);
if (sCount>lCount){
sCountWin.innerHTML = "Winner";
confettiS = new ConfettiGenerator({ target: 'confettiS', width: 600, height: 100 });
confettiS.render();
}
else if (sCount<lCount){
lCountWin.innerHTML = "Winner";
confettiL = new ConfettiGenerator({ target: 'confettiL', width: 600, height: 100 });
confettiL.render();
}
else{
sCountWin.innerHTML = "Tie";
lCountWin.innerHTML = "Tie";
}
restartButton.disabled=false;
document.removeEventListener("keydown", keyCount);
}
}, 1000);
}
});
restartButton.addEventListener("click", (restartTheGame) =>{
document.location.href = "";
});