-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin.js
35 lines (24 loc) · 975 Bytes
/
coin.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
function result(){
const randomValue=Math.random();
if(randomValue>=0.54)return 'Heads';
else return 'Tails'
}
document.getElementById('flip-button').addEventListener('click',()=>{
const resultElement=document.getElementById('result');
resultElement.innerHTML='Flipping..';
//selecting element onwhich animation we have to apply
const element=document.querySelector('.coin');
const element2=document.querySelector('.container');
//applying animation
element.style='animation:coinSpin 300ms linear infinite;';
element2.style='animation:coinFall 1.5s ease-out ;';
const Result=result();
setTimeout(()=>{element.style.animation='none';
element2.style.animation='none';
changingImg(Result);
resultElement.innerHTML=`It's ${Result}`
},1500);})
function changingImg(inputValue){
const element=document.querySelector('.coin-div')
element.innerHTML=`<img class="coin" src="${inputValue}.png">`
}