Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiza8980 authored Aug 2, 2023
1 parent 4005f9f commit d37a261
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 0 deletions.
Binary file added images/dice1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dice2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dice3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dice4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dice5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dice6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
<meta charset="utf-8">
<title>The Dice Game</title>
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css?family=Indie+Flower|Lobster" rel="stylesheet">

</head>

<body>

<div class="container">
<h1 id="resultText">Refresh Me!</h1>

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

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

</div>

<footer>
www 🎲 Shiza 🎲 com
</footer>
<script src="index.js"></script>

</html>

46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

// Function to get a random number between min (inclusive) and max (inclusive)
function getRandomDice() {
var randomNum = Math.floor(Math.random() * 6) + 1;
return "./images/dice" + randomNum + ".png";
}

var dice1 = document.querySelector(".img1");
var dice2 = document.querySelector(".img2");

dice1.src = getRandomDice();
dice2.src = getRandomDice();

// Function to get the dice number from the dice image URL
function getDiceNumberFromURL(url) {
const regex = /dice(\d+)\.png/;
const match = url.match(regex);
if (match) {
return parseInt(match[1]);
}
return null;
}

// Function to determine the winner or draw
function determineWinner() {
const dice1Value = getDiceNumberFromURL(dice1.src);
const dice2Value = getDiceNumberFromURL(dice2.src);

if (dice1Value > dice2Value) {
return "Player 1 Wins!🚩";
} else if (dice2Value > dice1Value) {
return "🚩Player 2 Wins!";
} else {
return "Draw!";
}
}

// Event listener to roll dice when the page is loaded (refreshed)
window.addEventListener('load', function() {
dice1.src = getRandomDice();
dice2.src = getRandomDice();

// Determine the winner and update the <h1> with the winner message
winnerMessage = determineWinner();
document.getElementById('resultText').innerHTML = winnerMessage;
});
41 changes: 41 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.container {
width: 70%;
margin: auto;
text-align: center;
}

.dice {
text-align: center;
display: inline-block;

}

body {
background-color: #393E46;
}

h1 {
margin: 30px;
font-family: 'Lobster', cursive;
text-shadow: 5px 0 #232931;
font-size: 6rem;
color: #4ECCA3;
}

p {
font-size: 2rem;
color: #4ECCA3;
font-family: 'Indie Flower', cursive;
}

img {
width: 60%;
}

footer {
margin-top: 5%;
color: #EEEEEE;
text-align: center;
font-family: 'Indie Flower', cursive;

}

0 comments on commit d37a261

Please sign in to comment.