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

              
                <p>Grace sent you a message <button onclick="reply();">Reply</button><button onclick="window.going = false;">Stop</button></p>
<textarea id="message"></textarea> <br>
<input id="input" /> <br>
<p id="grace"></p>
              
            
!

CSS

              
                
              
            
!

JS

              
                function interpret(code, state, size) {
    var bracketStack = [];
    var executionTape = new Uint8Array(size);
    var codePointer = 0;
    var isExecutingCode = true;
    var skippedBrackets = 0;
    var output = "";
    for(var index=0;index<code.length;index++) {
        if(isExecutingCode) {
            switch(code[index]) {
                case "+":
                    executionTape[codePointer]++;
                    break;
                case "-":
                    executionTape[codePointer]--;
                    break;
                case ".":
                    output += String.fromCharCode(executionTape[codePointer]);
                    break;
                case ",":
                    executionTape[codePointer] = ((state.length)?(state.charCodeAt(0)):0);
                    state = state.slice(1);
                    break;
                case ">":
                    codePointer++;
                    if(codePointer+1 > executionTape.length) throw `Error: Execution went past tape. Debug info: Execution index: ${index}. Tape pointer: ${codePointer}. Tape: [${executionTape.join(",")}]. Bracket indices: [${bracketStack.join(",")}]. Executing code: ${isExecutingCode}. Size: ${size}`;;
                    break;
                case "<":
                    codePointer--;
                    if(codePointer < 0) throw `Error: Execution went past tape. Debug info: Execution index: ${index}. Tape pointer: ${codePointer}. Tape: [${executionTape.join(",")}]. Bracket indices: [${bracketStack.join(",")}]. Executing code: ${isExecutingCode}. Size: ${size}`;
                    break;
                case "[":
                    if(executionTape[codePointer] == 0) {
                        isExecutingCode = false;
                        skippedBrackets++;
                    } else {
                        bracketStack.push(index-1);
                    }
                    break;
                case "]":
                    if(executionTape[codePointer] != 0) {
                        index = bracketStack.pop();
                    } else {
                        bracketStack.pop();
                    }
                    break;
                default:
            }
        } else {
            switch(code[index]) {
                case "[":
                    skippedBrackets++;
                    break;
                case "]":
                    skippedBrackets--;
                    if(skippedBrackets == 0) isExecutingCode = true;
                    break;
                default:
            }
        }
    }
  return output;
}
async function reply() {
  window.going = true;
  let code = document.getElementById("message").value;
  let input = document.getElementById("input").value;
  document.getElementById("grace").innerText = "Grace: ...";
  let steps = 0;
  let internal = "";
  let lines = code.split("\n");
  while((internal != input) && window.going) {
    if(Math.random() > 0.5) {
      var nums = lines[0].split(" ");
      var randomcode = lines[1]
    } else {
      var nums = lines[3].split(" ");
      var randomcode = lines[4]
    }
    try {
    internal = interpret(randomcode, internal, parseInt(nums[0])+parseInt(nums[1])*internal.length);
    } catch(e) {
      window.going = false;
      internal = e;
    }
    steps++;
    await new Promise((resolve => {setTimeout(resolve, 0)}))
  }
  let grace = window.going?"Ended in "+steps+" steps":"Stopped at "+steps+" steps, state "+internal.replace(/./g, function(c){return (((c.charCodeAt(0)<128)&&(c!="\\"))||(c.charCodeAt(0)<20))?c:"\\x"+c.charCodeAt(0).toString(16)}); // thanks to https://stackoverflow.com/questions/7499473/need-to-escape-non-ascii-characters-in-javascript/48954674#48954674
  document.getElementById("grace").innerText = "Grace: "+grace;
}
              
            
!
999px

Console