-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (34 loc) · 1.16 KB
/
index.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
function player1(){
var Score=Math.floor(Math.random()*6)+1;
var Img=document.getElementById('p1-img');
Img.src=`images/dice${Score}.png`;
return Score
}
function player2(){
let Score=Math.floor(Math.random()*6)+1;
var Img=document.getElementById('p2-img');
Img.src=`images/dice${Score}.png`;
return Score
}
let playAgainButton = document.querySelector('.btn');
playAgainButton.addEventListener('click', function(event) {
playAgainButton.innerHTML="Play Again!"
let result=document.querySelector('.heading h1');
let p1heading=document.querySelector('.player-1 h3');
let p2heading=document.querySelector('.player-2 h3');
let p1score=player1();
let p2score=player2();
if (p1score>p2score){
result.innerHTML="Player 1 win";
p1heading.innerHTML="You Win 🎉";
p2heading.innerHTML="You Lose😢";
}else if (p1score<p2score){
result.innerHTML="Player 2 win"
p2heading.innerHTML="You Win 🎉";
p1heading.innerHTML="You Lose😢";
}else{
result.innerHTML="Draw!😊"
p1heading.innerHTML="Draw!😊";
p2heading.innerHTML="Draw!😊";
}
});