JSFiddle - React, Tailwind, and code Playground

by Artem

HTML

<textarea id="code">return "hi";</textarea>
<button id="button">Поехали</button>
<pre id="output"></pre>

JavaScript

'use strict';
var textarea, output, btn, executeCode, showResult;
textarea = document.getElementById('code');
output = document.getElementById('output');
btn = document.getElementById('button');

executeCode = function() {
  var textValue, func, res;
  textValue = textarea.value;
  try {
  	 func = new Function(textValue)();
  } catch(e) {
  	console.log('Error: ', e);
  }
  showResult(func);
};

showResult = function(code) {
  output.textContent = code;
};

btn.addEventListener('click', executeCode);