Skip to content

Commit

Permalink
competed the challenge.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Eugene-Barasu committed Aug 26, 2024
1 parent 697956c commit 859631f
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@

// get a random number between 1 - 6
let randomNumber1 = Math.floor((Math.random() * 6) + 1);
console.log(randomNumber1);

let leftDice = document.querySelector("#img1");
// get a second number between 1 - 6
let randomNumber2 = Math.floor((Math.random() * 6) + 1);
console.log(randomNumber1);

// selecting the image from the HTML file respectively
let leftDice = document.querySelector(".img1");
let rightDice = document.querySelector(".img2");

let imageSources = [
`./images/dice1.png`,
Expand All @@ -13,4 +19,23 @@ let imageSources = [
`./images/dice6.png`,
];

leftDice.setAttribute(`src`, imageSources[randomNumber1 - 1]);
// changing the images using the src (source) attribute
leftDice.setAttribute(`src`, imageSources[randomNumber1 - 1]);
rightDice.setAttribute(`src`, imageSources[randomNumber2 - 1]);

// to change the h1 text to display which one won
let output = document.querySelector(`h1`);

// to check the winner using "if else"
if( randomNumber1 > randomNumber2){
output.innerText = `Player 1 won`;
} else if ( randomNumber2 > randomNumber1){
output.innerText = `Player 2 won`;
} else {
output.innerText = `It's a draw`;
}





0 comments on commit 859631f

Please sign in to comment.