title: How do I run a function from a make-shift console?
body: <p>I am attempting to create a console. Let's say I a function <code>foo()</code> and I enter it into the "console". The console should run that function. I attempted the following:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var $console = $('.console');
  var console = {
   log: function(txt) {
    $console.append(txt + '&lt;br&gt;');
   },
   clear: function() {
    $console.text(' ');
   }
  }
  function foo() {
    console.log('foo ran');
  }
  var bKeys = [];
  $('body').keydown(function(event) {
   if (event.which === 13) {
    //run the provided function from the input
      ($('.run').text())();
   }
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.console {
   position: absolute;
   right: 0px;
   top: 0px;
   background-color: #fff;
   width: 300px;
   height: 100%;
   box-shadow: 0px 0px 5px #444;
   overflow-y: auto;
  }
  .run {
   position: fixed;
   bottom: 0px;
   width: 295px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class='console'&gt;&lt;input class='run' type='text' placeholder='Run a command...'/&gt;Console: &lt;br&gt; &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>What I tried was returning the text and trying to run that function after <kbd>Enter</kbd> is pressed in the <code>&lt;input&gt;</code>. However, that isn't working. How can I run a typed function from <code>&lt;input&gt;</code>?</p>