Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main.js #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions Dicee Game/main.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
var rendom1 = Math.floor(Math.random() * 6)+1;
var rendom2 = Math.floor(Math.random() * 6)+1;
var rendomImg1 = "images/dice"+rendom1+".png"
var rendomImg2 = "images/dice"+rendom2+".png"
// Declaring variables and creating random images
const random1 = Math.floor(Math.random() * 6) + 1;
const random2 = Math.floor(Math.random() * 6) + 1;
const randomImg1 = `images/dice${random1}.png`;
const randomImg2 = `images/dice${random2}.png`;

function winer(){
image();
if(rendom1 < rendom2){
document.querySelector("h1").innerHTML="Player 2 wins";
}else if(rendom1 === rendom2){
document.querySelector("h1").innerHTML="Drow"
}else {
document.querySelector("h1").innerHTML="Player 1 wins"
}
}
// Displaying images and identifying the winner
function displayResult() {
document.querySelector(".img1").setAttribute("src", randomImg1);
document.querySelector(".img2").setAttribute("src", randomImg2);

function image(){
document.querySelector(".img1").setAttribute("src", rendomImg1);
document.querySelector(".img2").setAttribute("src", rendomImg2);
if (random1 < random2) {
document.querySelector("h1").innerHTML = "Player 2 wins";
} else if (random1 === random2) {
document.querySelector("h1").innerHTML = "Draw";
} else {
document.querySelector("h1").innerHTML = "Player 1 wins";
}
}
winer();

function refreshPage(){
window.location.reload();

}


// Calling the function to display the result and identify the winner
displayResult();

// Page refresh on click of the refresh button
document.querySelector("button").addEventListener("click", () => {
location.reload();
});