#JavaScript (sample answer)

Interpreting JavaScript using JavaScript is somewhat useless, but this shows what I expect your interpreter snippets to roughly behave like.

<!-- begin snippet: js hide: false -->

<!-- language: lang-js -->

    var x, y;

    function example() {
      document.getElementById('code').value = "var lines = x.split('\\n')\nvar sum = 0\nfor (var i = 0; i < lines.length; i++) {\n  sum += parseInt(lines[i])\n}\ny = sum"
      document.getElementById('input').value = "1\n2\n3"
      run()
    }

    function run() {
      var run = null, example = null; //shadow other globals
      x = document.getElementById('input').value
      eval(document.getElementById('code').value)
      document.getElementById('output').value = String(y)
    }

<!-- language: lang-css -->

    #output {
      background-color: #f0f0f0;
    }

    #run {
      font-size: 120%;
    }

<!-- language: lang-html -->

    JavaScript Code:
    <br>
    <textarea id='code' rows='12' cols='60'></textarea>
    <br>
    Input String (global variable x):
    <br>
    <textarea id='input' rows='6' cols='60'></textarea>
    <p><input id='run' type='button' value='Run' onclick='run()'></p>
    Output (global variable y, initially undefined):
    <br>
    <textarea id='output' rows='6' cols='60'></textarea>
    <p><a id='example' href='javascript:void(0)' onclick='example()'>Example: Sum Numbers</a><p>
    <p>(Since there is no stdin/stdout the input string is assigned to the global variable x and the output is the global variable y cast to a string.)</p>

<!-- end snippet -->

To copy the snippet's raw Markdown click "edit" below and take everything from `<!-- begin snippet...` to `...end snippet -->`. (I can't seem to display the raw Markdown without creating another snippet.)