Number Dice

Preview

Html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script
      src="https://kit.fontawesome.com/1935d064dd.js"
      crossorigin="anonymous"
    ></script>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <div class="container">
      <div class="container2">
        <h1>Number Dice</h1>
        <span class="number"></span>
        <hr />
        <div class="buttons">
          <button class="generate"><i class="fas fa-dice"></i> Roll</button>
        </div>
      </div>
    </div>
    <script src="script.js"></script>
  </body>
</html>

Preview

CSS

@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap");
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  font-family: "Poppins", sans-serif;
  height: 100vh;
  overflow: hidden;
}
p {
  font-size: 1.6rem;
  line-height: 1.5;
}
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
.container2 {
  width: 40rem;
  border: 1px solid white;
  padding: 3rem;
  background-color: #5f3dc4;
  color: white;
  text-align: center;
  border-radius: 5px;
}
hr {
  width: 50%;
  margin: 10px auto 0;
  border-top: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.number {
  font-size: 4rem;
}
.buttons button {
  padding: 1rem;
  margin: 3rem 1rem 1rem;
  font-size: 1.5rem;
  color: black;
  font-weight: 700;
  border: none;
  outline: none;
  border-radius: 3px;
  cursor: pointer;
}

JavaScript

const number = document.querySelector(".number");
const btn = document.querySelector(".generate");
const generateNumber = () => {
  const randomNumber = Math.floor(Math.random() * 6 + 1);
  number.innerHTML = randomNumber;
};
btn.addEventListener("click", generateNumber);
generateNumber();

Preview

Latest

Leave A Reply

Please enter your comment!
Please enter your name here