-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
44 lines (40 loc) · 1.38 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="Style.css">
</head>
<body>
<div id="nav">
<nav id="navbar">
<div id="text"><h1>DICE GAME!</h1></div>
</nav>
</div>
<div id="game">
<img src="dice-six-faces-6.png" class="player1">
<img src="dice-six-faces-6.png" class="player2">
</div>
<div class="btn">
<button class="btn1" onclick="player1()">PLAYER</button>
</div>
<script type="text/javascript">
function player1(){
var n=Math.floor(Math.random()*6)+1;
document.querySelector("img.player1").setAttribute("src","dice-six-faces-"+n+".png");
var x=Math.floor(Math.random()*6)+1;
document.querySelector("img.player2").setAttribute("src","dice-six-faces-"+x+".png");
if(n<x){
document.querySelector("h1").innerHTML="PLAYER2 WINS!"
}
else if(n>x){
document.querySelector("h1").innerHTML="PLAYER1 WINS!"
}
else{
document.querySelector("h1").innerHTML="DRAW!"
}
}
</script>
</body>
</html>