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


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


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.


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.


                <p>Do a prime number search from <input id="from" value="1"> to <input id="to" value="500000" size="200">.</p>
<button onclick="doSearch()">Start Searching</button>

<div id="primeContainer">

<div id="status"></div>



                body {
  font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
  margin: 20px;

#primeContainer {
  border: solid 1px black;
  padding: 3px;
  height: 300px;
  max-width: 500px;
  overflow: scroll;
  overflow-x: hidden;
  font-size: x-small;
  margin-top: 20px;
  margin-bottom: 10px;

input {
  width: 80px;

button {
  padding: 3px;

p {
  margin-bottom: 3px;

#status {
  color: darkred;



                function doSearch() {
  // Get the two numbers in the text boxes. This is the search range.
  var fromNumber = document.getElementById("from").value;
  var toNumber = document.getElementById("to").value;

  var statusDisplay = document.getElementById("status");
  statusDisplay.innerHTML = "Starting new search...";    
  // Perform the search.
  var primes = findPrimes(fromNumber, toNumber);

  // Take the results, loop over it,
  // and paste it into one long piece of text.
  var primeList = "";
  for (var i=0; i<primes.length; i++) {
    primeList += primes[i];
    if (i != primes.length-1) primeList += ", ";
  // Show the prime number list on the page.
  var primeContainer = document.getElementById("primeContainer");
  primeContainer.innerHTML = primeList;

  var statusDisplay = document.getElementById("status");
  if (primeList.length == 0) {
    statusDisplay.innerHTML = "Search didn't find any results.";
  else {
    statusDisplay.innerHTML = "The results are here!";

function findPrimes(fromNumber, toNumber) {

  // Create an array containing all integers
  // between the two specified numbers.
  var list = [];
  for (var i=fromNumber; i<=toNumber; i++) {
    if (i>1) list.push(i);

  // Test for primes.
  var maxDiv = Math.round(Math.sqrt(toNumber));
  var primes = [];

  for (var i=0; i<list.length; i++) {
    var failed = false;
    for (var j=2; j<=maxDiv; j++) {
      if ((list[i] != j) && (list[i] % j == 0)) {
        failed = true;
      } else if ((j==maxDiv) && (failed == false)) {

  return primes;