cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <link href="https://fonts.googleapis.com/css?family=Source+Serif+Pro" rel="stylesheet">

<div class = 'container-flex'>

<h1>Random Quote Generator</h1>  
  
<div id = 'quote'> </div>

<button id = 'submit'>New Quote</button>

</div>
            
          
!
            
              body {
font-family: 'Source Serif Pro', serif;
width: 100vw;
background: linear-gradient(90deg, #dbdfe0, #eef2f3);
}

.container-flex {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 600px;
  height: 350px;
  margin: 0 auto;
  text-align: center;
  padding: 50px 30px 0 30px;
}

#quote {
  font-size: 20px;
}

#submit {
  border: none;
  background-color: #fff;
  font-family: 'Source Serif Pro', serif;
  font-size: 16px;
  cursor: pointer;
  transition: 0.2s all linear;
  height: auto;
  width: auto;
  border-radius: 2px;
  margin-top: 30px;
}

#submit:hover {
  background-color: #282828;
  color: #fff;
}


#submit:focus {
  outline: none;
}

p {
  display: table-cell;
  vertical-align: middle;
  animation: fadeIn 2s 1;
  padding: 0 10px 20px 10px;
  color: #fff;
  background-color: #282828;
  width: 800px;
  height: 100px;
  text-align: center;
  border-radius: 3px;
}

  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
}
            
          
!
            
              var quotes;
quotes = [ ' "Success is the sum of small efforts, repeated day in and day out." ',
          ' "Everything is created twice, first in the mind, then in reality." ',
          ' "The secret is here in the present. If you pay attention to the present you can improve upon it. And, if you can improve the present, what comes later will also be better." ', 
          ' "Believe you can and you’re halfway there." ', 
          ' "Mistakes are the portals of discovery." ', 
          ' "Great things come from hard work and perseverance. No excuses." ', 
          ' "The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty." ', 
          ' "Whether you think you can or think you can’t, you’re right." ', 
          ' "You are never too old to set another goal or to dream a new dream." ', 
          ' "Do not wait; the time will never be ‘just right.’ Start where you stand, and work with whatever tools you may have at your command, and better tools will be found as you go along." ', 
         ];

document.getElementById('submit').addEventListener('click', function(){
  
  var randomNum = Math.floor((Math.random() * quotes.length));
  
  var el = document.getElementById('quote');
  el.innerHTML = '<p>' + quotes[randomNum];
  
})


            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console