Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="Random Number Generator" content="width=device-width, initial-scale=1.0">
    <title>Random Number Generator.</title>
</head>
<body>
    <link rel="stylesheet" href="style.css">
    <h1 class="gen">Random Number Generator</h1>
    <h2 id="num">0</h2>
    <h1 id="id">Unknown</h1>
    <h1>Total</h1>
    <h2 id="total">0</h2>
    <button class="btn" onclick="random()">Generator</button>
    <script src="index.js"></script>
</body>
</html>
              
            
!

CSS

              
                
@import url("https://fonts.googleapis.com/css2?family=Poppins&display=swap");

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 0;
  display: grid;
  place-items: center;
  background-color: #b1b1b1;
  font-size: 15px;
  font-weight: bold;
  font-family: "Poppins", sans-serif;
}
.gen {
    border-color: #121212;
    display: block;
    border-radius: 3px;
}

.btn {
  padding: 10px 25px;
  border: none;
  border-radius: 5px;
  background-color: #4cf7a4;
  color: #121212;
  font-size: 25px;
  font-weight: bold;
  font-family: "Poppins", sans-serif;
  cursor: pointer;
  transition: 0.15s;
  box-shadow: 10px -10px #222222;
}

.btn:hover {
  box-shadow: -10px 10px #121212;
  color: #fbfbfb;
  letter-spacing: 1px;
  background-color: #276088;
}

.btn:focus {
  outline: none;
}

              
            
!

JS

              
                let total = 0;


function random() {
  let num = Math.floor(Math.random() * 11);
  document.getElementById("num").innerText = num;
        
  let a = document.getElementById("id");    // creating a variable to short the code. LOL.

    
  function odd() {                          // if called this will change the text to "Number id odd".
    a.innerText = "Number is odd.";
  }
  function even() {                         // if called this will change the text to "Number is even".
    a.innerText = "Number is even.";
  }
    
    
  if (num % 2 == 0)  {  // if the number is even
    even();         // the even fuction will be called.
  } else {  // if not 
    odd();          // then odd fuction will be called.
  }
  
  let equl = document.getElementById("total");  // creating a variable to short the code. LOL.
  total += num; // will add the previous value and number generated.
  equl.innerText = total;       // this will change the inner text to the total amount
}

              
            
!
999px

Console