Skip to content

Commit

Permalink
Merge pull request #7 from Babunshil/shil
Browse files Browse the repository at this point in the history
Changes the name of the players as per mention in the issue #1
  • Loading branch information
Chirag1309 authored Apr 13, 2023
2 parents a68d2ec + e3cbcbd commit 3f62bb3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
8 changes: 5 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ <h1>Refresh Me</h1>


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

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

</div>
<button type="button" value="Reload Page" onclick="window.location.reload(true)">Play Again</button>
<button class="play-button">Play Again</button>


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

</body>
Expand Down
42 changes: 28 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
var randomVar=Math.floor(Math.random()*6)+1;
var randomDice="dice"+randomVar+".png";
var x="images/"+randomDice;
document.querySelectorAll("img")[0].setAttribute("src",x);
var randomVar2=Math.floor(Math.random()*6)+1;
var randomDice2="dice"+randomVar2+".png";
var y="images/"+randomDice2;
document.querySelectorAll("img")[1].setAttribute("src",y);
if(randomVar2>randomVar){
document.querySelector("h1").innerHTML="Player2 Wins!";
}else if(randomVar2<randomVar) {
document.querySelector("h1").innerHTML="Player1 Wins";
}else{
document.querySelector("h1").innerHTML="DRAW!!";
//Taking user name
const userName = prompt("Please enter your name.");
document.querySelector(".player-name").innerHTML = userName;


const playAgain = document.querySelector(".play-button");
playAgain.addEventListener("click", () => {
gamePlay();
});

const gamePlay = () => {
var randomVar=Math.floor(Math.random()*6)+1;
var randomDice="dice"+randomVar+".png";
var x="images/"+randomDice;
document.querySelectorAll("img")[0].setAttribute("src",x);
var randomVar2=Math.floor(Math.random()*6)+1;
var randomDice2="dice"+randomVar2+".png";
var y="images/"+randomDice2;
document.querySelectorAll("img")[1].setAttribute("src",y);
if(randomVar2>randomVar){
document.querySelector("h1").innerHTML="Player2 Wins!";
}else if(randomVar2<randomVar) {
document.querySelector("h1").innerHTML="Player1 Wins";
}else{
document.querySelector("h1").innerHTML="DRAW!!";
}
}


0 comments on commit 3f62bb3

Please sign in to comment.