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

              
                <h1>Happy Fibonacci day!</h1>
<p>
  Maybe I'm a day late. Sorry. Here's a way to calculate the Fibonacci Sequence using vanilla JavaScript with recursion. It gets a lot faster <i>without recursion</i>, though. <br>
  This version is optimized so it's almost as fast as the iterative solution, but this solution is a little prettier and could be written as a one-liner.<br>
  In mathematics, the Fibonacci sequence is characterized by every number after the first two being the sum of the two preceding numbers:<br/>
  <code>
    1, 1, 2, 3, 5, 8, 13, 21, 34, ...
  </code><br/>
  Often, especially in modern usage, the sequence is preceded by a zero:<br/>
  <code>
    0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
  </code><br/>
  November 23 (11/23) is Fibonacci day because when the date is written in the MM/DD format, the digits are the start of the sequence: 1,1,2,3
</p>
<p id='result'></p>
              
            
!

CSS

              
                body {
  padding: 1em;
}
#result {
  font-family: monospace;
  padding: .3em;
  background: black;
  color: green;
}
              
            
!

JS

              
                const r = Array();
function optimizedFib(n, a = 1, b = 0) {
  r.push(b);
  if (n === 0) {
    return b;
  }
  return optimizedFib(n - 1, a + b, a);
}

optimizedFib(1000);
var out = document.getElementById('result');
r.forEach(el => {
  result.append(el + ", ");
})
              
            
!
999px

Console