-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (46 loc) · 1.13 KB
/
script.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
// require
let coin = document.querySelector(".coin");
let flipBtn = document.querySelector("#flip-button");
const result = document.querySelector('.count');
// variable
let heads = 0;
let tails = 0;
// toss
flipBtn.addEventListener("click", () => {
let i = Math.floor(Math.random() * 10 + 1);
coin.style.animation = "none";
// head or tail
if(i % 2 == 0){
setTimeout(function(){
coin.style.animation = "spin-heads 6s forwards";
}, 100);
heads++;
}
else{
setTimeout(function(){
coin.style.animation = "spin-tails 6s forwards";
}, 100);
tails++;
}
setTimeout(updateStats, 6000);
var audio = document.getElementById('myAudio');
audio.play();
disableButton();
});
// updation
function updateStats(){
if(heads > 0){
document.querySelector("#count").textContent = `Head`;
}else{
document.querySelector("#count").textContent = `Tail`;
}
heads = 0;
tails = 0;
}
// disabled
function disableButton(){
flipBtn.disabled = true;
setTimeout(function(){
flipBtn.disabled = false;
},10000);
}