-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Babunshil/shil
Changes the name of the players as per mention in the issue #1
- Loading branch information
Showing
2 changed files
with
33 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!"; | ||
} | ||
} | ||
|
||
|