Pen Settings



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


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.


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.


                <h1>Gramma's Dishcloth</h1>
<p>A JavaScript implementation of knitting. See <a href="" target="blank">Gramma's Dishcloth</a> for the full knitting pattern.</p>

<button id="knit" onclick="knit(event)">Knit Dishcloth</button>

<div id="dishcloth"></div>




                // Cast on 3 stitches
var dishcloth = [];

// Knit across

// Knit 1, knit front & back, knit 1

//*K2, yo, knit to end.*
// Repeat from * to * until there are 45 stitches on your needle.
for (var j = 2; j < 45; j++) {
  var prow = dishcloth[j-1];
  var row = [];
  for (var k = 0; k <= prow.length; k++) {
    // Yarn over if it is the third stitch
    if (k === 2) {
    } else {
      // knit
  // As a pair of rows acts like a stack
  if (j % 2 == 0) {
    // push even rows on
  } else {
    // reverse odd rows and then push them on

// Output dishcloth array on button click
function knit(event) {
  // just because I like to do this
  // create an empty string
  var cloth = "";
  for (var i = 0; i < dishcloth.length; i++) {
    // Add each internal array as a string to cloth with a break
    cloth += dishcloth[i].toString() + "<br />";
  // Find the dishcloth element and replace it's innnerHTML with the value of cloth
  document.getElementById("dishcloth").innerHTML = cloth;