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>
  <body>
    <h1>UI callback function</h1>
    <button maxValue="100">Primes up to 100</button><p/>
    <button maxValue="10000">Primes up to 10,000</button><p/>
    <button maxValue="10000000">Primes up to 10,000,000</button><p/>
    <button maxValue="10000000000">Primes up to 10,000,000,000</button>
    <p>
      Resulting primes: <div id="result">Waiting for click...</div></p>
  </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                console.log("About to add UI callbacks");
const result = document.getElementById("result");
const btns = document.getElementsByTagName("button");
for (let k = 0; k < btns.length; k++) {
  btns[k].addEventListener("click", primeNumbersTo);
}


function primeNumbersTo(event)
{
    const max = event.target.getAttribute("maxValue");
    var store  = [], i, j, primes = [];
    for (let i = 2; i <= max; ++i) 
    {
        if (!store [i]) 
          {
            primes.push(i);
            for (let j = i << 1; j <= max; j += i) 
            {
                store[j] = true;
            }
        }
    }
    console.log("Primes from max %s: %s", max, primes);
    result.innerHTML = primes
    return primes;
}

console.log("Finished adding UI callbacks")
console.log("I'm a really urgent log message");

              
            
!
999px

Console