Skip to content

Commit bff46e2

Browse files
Initial dice game
1 parent ec2c0a4 commit bff46e2

9 files changed

+81
-0
lines changed

dice.css

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
body{
2+
background-color: rgb(101, 84, 100);
3+
height: 100vh;
4+
font-family: 'Roboto Mono', monospace;
5+
margin-top: 5%;
6+
7+
}
8+
.container{
9+
text-align: center;
10+
}
11+
img{
12+
height: 150px;
13+
width: 150px;
14+
15+
}
16+
figure{
17+
display: inline-block;
18+
}
19+
button{
20+
cursor: pointer;
21+
width: 100px;
22+
padding: 10px;
23+
border-radius: 10%;
24+
font-size: 15px;
25+
font-weight: 600;
26+
background-color: steelblue;
27+
28+
}

dice.html

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Dice Game</title>
5+
<link rel="stylesheet" type="text/css" href="dice.css">
6+
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital@1&display=swap" rel="stylesheet">
7+
</head>
8+
<body>
9+
<div class="container">
10+
<h1>DICE GAME</h1>
11+
<button id="btn">Refreh</button>
12+
<h3>Refresh to know the winner</h3>
13+
14+
<br>
15+
<figure>
16+
<img id="p1" src="dice1.png">
17+
<figcaption>Player 1</figcaption>
18+
</figure>
19+
<figure>
20+
<img id="p2" src="dice2.png">
21+
<figcaption>Player 2</figcaption>
22+
</figure>
23+
24+
</div>
25+
26+
<script type="text/javascript" src="dice.js"></script>
27+
</body>
28+
</html>

dice.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
var button = document.querySelector("#btn");
3+
var img1 = document.querySelector("#p1");
4+
var img2 = document.querySelector("#p2");
5+
var head = document.querySelector("h3");
6+
var r1,r2;
7+
8+
function random(){
9+
var r = Math.floor(Math.random() * 6) +1 ;
10+
return "dice" + r + ".png";
11+
}
12+
13+
button.addEventListener("click", function(){
14+
img1.setAttribute("src" , r1 = random());
15+
img2.setAttribute("src" , r2 = random());
16+
if(r1[4] > r2[4]){
17+
head.textContent = "Player 1 Wins"
18+
}
19+
else if(r1[4] < r2[4]){
20+
head.textContent = "Player 2 Wins"
21+
}
22+
else if(r1[4] == r2[4]){
23+
head.textContent = "It's a tiee"
24+
}
25+
});

dice1.png

2.5 KB
Loading

dice2.png

2.16 KB
Loading

dice3.png

2.38 KB
Loading

dice4.png

2.55 KB
Loading

dice5.png

2.76 KB
Loading

dice6.png

2.91 KB
Loading

0 commit comments

Comments
 (0)