Skip to content

Commit

Permalink
final prepared
Browse files Browse the repository at this point in the history
  • Loading branch information
divyansh-prks committed Jun 21, 2023
1 parent 26c17c4 commit e47cad1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
17 changes: 10 additions & 7 deletions dicee.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,29 @@

</head>
<body>


<div class="container">
<h1>Refresh Me</h1>
<h1>Refresh Me</h1>

<div class="dice">
<p>Player 1</p>
<img class="img1" src="">
<img class="img1" src="images/dice6.png">
</div>

<div class="dice">
<p>Player 2</p>
<img class="img2" src="">
<img class="img2" src="images/dice6.png">
</div>

</div>

<script src="index.js" charset="utf-8"></script>

</body>
</body>

<footer>
www 🎲 App Brewery 🎲 com
</footer>
</html>
<footer>
Copyright 2023 Made By ❤️ of Divyansh Pratap Singh
</footer>
</html>
34 changes: 20 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
var randomNumber1 = Math.floor(Math.random() *6) + 1;
var randomDiceImage = "dice" + randomNumber1 + ".png" ;
var randomimagesource = "images/"+ randomDiceImage ;

var randomNumber1 = Math.floor(Math.random() * 6) + 1; //1-6

var randomDiceImage = "dice" + randomNumber1 + ".png"; //dice1.png - dice6.png

var randomImageSource = "images/" + randomDiceImage; //images/dice1.png - images/dice6.png

var image1 = document.querySelectorAll("img")[0];
image1.setAttribute("src", randomimagesource);

image1.setAttribute("src", randomImageSource);

var randomNumber2 = Math.floor(Math.random()*6) +1;
var randomDiceImage2 = "dice" + randomNumber2 + ".png" ;
var randomimagesource2 = "images/dice" + randomNumber2 + ".png" ;
document.querySelectorAll("img")[1].setAttribute("src", randomimagesource2);
image1.setAttribute("src", randomimagesource);

var randomNumber2 = Math.floor(Math.random() * 6) + 1;

var randomImageSource2 = "images/dice" + randomNumber2 + ".png";

document.querySelectorAll("img")[1].setAttribute("src", randomImageSource2);


//If player 1 wins
if (randomNumber1 > randomNumber2) {
document.querySelector("h1").innerHTML = "Player 1 wins !"
document.querySelector("h1").innerHTML = "🚩 Play 1 Wins!";
}
else if(randomNumber2 > randomNumber1) {
document.querySelector("h1").innerHTML = "Player 2 Wins";
else if (randomNumber2 > randomNumber1) {
document.querySelector("h1").innerHTML = "Player 2 Wins! 🚩";
}
else {
document.querySelector("h1").innerHTML = "Draw";
}
document.querySelector("h1").innerHTML = "Draw!";
}

0 comments on commit e47cad1

Please sign in to comment.