Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                h1.header Dice Roller

// Shows a question mark whilst loading
img(src="https://bit.ly/dice-unknown")#dice

// When you click the div, it executes rollThatDice()
div(onclick="rollThatDice()") Roll That Dice

// A link to the roll sound you hear
audio(src="https://bit.ly/dice-sound")#audio
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Indie+Flower')

body
  width: 100vw
  height: 100vh
  font-family: 'Indie Flower', sans-serif
  background-color: #303030
  color: #fff
  display: flex
  justify-content: center
  align-items: center
  flex-direction: column
  user-select: none
  
h1
  font-size: 25vh
  
@keyframes spindice
  0%
    transform: rotate(0deg)
    filter: blur(5px)
  100%
    transform: rotate(360deg)
    filter: blur(5px)
  
img
  width: 40vh
  padding: 5vh
  animation: none
  
div
  font-size: 10vh
  color: #fff
  background-color: #d72e2e
  height: auto
  border: none
  padding: 5vh 10vh
  border-radius: 50px
  cursor: pointer
  transition: all 0.5s
  &:hover
    background-color: #fff
    color: #303030
    
              
            
!

JS

              
                var diceFaces = [
"https://bit.ly/dice-unknown",
"https://bit.ly/dice-one",
"https://bit.ly/dice-two",
"https://bit.ly/dice-three",
"https://bit.ly/dice-four",
"https://bit.ly/dice-five",
"https://bit.ly/dice-six"
];

// Cleans up code later
var image = document.getElementById("dice");
var audio = document.getElementById("audio");

// Gets a random integer, min & max inclusive
function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

function rollThatDice() {
  audio.currentTime = 0;
  image.style.animation = "spindice 0.25s"
  setTimeout(function() {
    image.setAttribute("src", diceFaces[getRandomInt(1, 6)]);
                       }, 125);
  
  setTimeout(function(){ image.style.animation = "none"
                       }, 250);
  audio.play();
}

document.addEventListener("DOMContentLoaded", function(event) {
    rollThatDice();
});
              
            
!
999px

Console