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

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

              
                <div>
  <button>Generate Fact</button>
</div>
<ul></ul>
              
            
!

CSS

              
                body {
  background-color: #333;
  color: #DDD;
  font-size: 21pt;
  padding: 1em;
}
div {
  text-align: center;
}
button {
  border: 1px solid currentColor;
  background-color: transparent;
  color: currentColor;
  font-size: inherit;
  border-radius: 3px;
  box-shadow: 1px 1px 2px 1px black;
  cursor: pointer;
}
button:hover {
  box-shadow: inset 1px 1px 2px 1px black;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  border-bottom: 1px solid currentColor;
  padding: 1em;
}
              
            
!

JS

              
                console.clear();
let raw = `Did you know that (
    the ( Fall | Spring ) Equinox |
    the ( Winter | Summer ) ( Solstice | Olympics ) |
    the ( Earliest | Latest ) ( Sunrise | Sunset ) |
    Daylight ( Saving | Savings ) Time |
    Leap ( Day | Year ) |
    Easter |
    the ( Harvest | Super | Blood ) Moon |
    Toyota Truck Month |
    Shark Week )
(
    happens ( earlier | later | at the wrong time ) every year |
    drifts out of sync with the (
        Sun |
        Moon |
        Zodiac |
        ( Gregorian | Mayan | Lunar | iPhone ) Calendar |
        atomic clock in Colorado ) |
    might ( not happen | happen twice ) this year )
because of (
    time zone legislation in ( Indiana | Arizona | Russia ) |
    a decree by the pope in the 1500s |
    ( precession | libration | nutation | libation | eccentricity | obliquity ) of the (
        Moon |
        Sun |
        Earth's axis |
        equator |
        prime meridian |
        ( international date | mason-dixon ) line ) |
    magnetic field reversal |
    an arbitrary decision by ( Benjamin Franklin | Isaac Newton | FDR ) )
? 
Apparently (
    it causes a predictable increase in car accidents. |
    that's why we have leap seconds. |
    scientists are really worried. |
    it was even more extreme during the (
        Bronze Age. |
        Ice Age. |
        Cretaceous. |
        1990s. ) |
    there's a proposal to fix it, but it (
        will never happen. |
        actually makes things worse. |
        is stalled in congress. |
        might be unconstitutional. ) |
    it's getting worse and no one knows why. )`;

function pickOptions(string){
  return string.replace(/\s+\(\s*( [^()]+)\s*\)/g, (_all, options) =>
    options
      .split(/\s*\|/)
      .sort(() => Math.random() - 0.5)[0]
  );
}

function run() {
  const li = document.createElement('li');
  list.prepend(li);
  let previousResult = "";
  let result = pickOptions(raw.replace(/\s+/gm, ' '));
  while (result != previousResult) {
    previousResult = result;
    result = pickOptions(previousResult);
  }
  li.textContent = result.replace(/(\w) ([.,,?])/g, "$1$2");
}

const button = document.querySelector('button');
const list = document.querySelector('ul');
button.addEventListener('click', run);
run();
              
            
!
999px

Console