title: Calculator: String Into Math Operation (JavaScript)
body: <p>How can I convert a string to a mathematical operation? I can't use eval. Any suggestions?
  This is what I have so far. I split the string into an array, but how do I turn '=' ,'-' etc. into actual mathematical operations. Also, I know I could use parseInt to turn 'number' into an actual number, but how would that look in the code? Not sure how to start.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/&gt;
      &lt;title&gt;JavaScript HW3&lt;/title&gt;
      &lt;script type="text/javascript"&gt;
        function display(num) {
          var node = document.getElementById("display");  
          node.value+=num;    
        }
  
        function result(){
          document.getElementById("display").value = (document.getElementById("display").value).split("");
        }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt; 
      &lt;h1&gt;Simple calculator&lt;/h1&gt;
  
  
      &lt;form action="" method="get"&gt;
        &lt;p&gt;
          &lt;input type="text" id="display"/&gt;       
        &lt;/p&gt;
      &lt;/form&gt;
  
      &lt;form action=""  method="get"&gt;
        &lt;div class="button"&gt;
          &lt;input type="button" class="btn" name="b7" value="7" onclick='display("7")'/&gt;
          &lt;input type="button" class="btn" name="b8" value="8" onclick='display("8")'/&gt;
          &lt;input type="button" class="btn" name="b9" value="9" onclick='display("9")'/&gt;
          &lt;input type="button" class="btn" name="db" value="/" onclick='display("/")'/&gt;
          &lt;br/&gt;
          &lt;input type="button" class="btn" name="b4" value="6" onclick='display("6")'/&gt;
          &lt;input type="button" class="btn" name="b5" value="5" onclick='display("5")'/&gt;
          &lt;input type="button" class="btn" name="b6" value="4" onclick='display("4")'/&gt;
          &lt;input type="button" class="btn" name="mb" value="*" onclick='display("*")'/&gt;
          &lt;br/&gt;    
          &lt;input type="button" class="btn" name="b1" value="3" onclick='display("3")'/&gt;
          &lt;input type="button" class="btn" name="b2" value="2" onclick='display("2")'/&gt;
          &lt;input type="button" class="btn" name="b3" value="1" onclick='display("1")'/&gt;
          &lt;input type="button" class="btn" name="mib" value="-" onclick='display("-")'/&gt;
          &lt;br&gt;&lt;/br&gt;
  
          &lt;input type="button" class="btn" name="db" value="." onclick='display(".")'/&gt;
          &lt;input type="button" class="btn" name="b0" value="0" onclick='display("0")'/&gt;
          &lt;input type="button" class="btn" name="eb" value="=" onclick='result("")'/&gt;
          &lt;input type="button" class="btn" name="ab" value="+" onclick='display("+")'/&gt;
          &lt;br/&gt;
        &lt;/div&gt;
      &lt;/form&gt;
  
      &lt;!-- W3C XHTML Validation logo--&gt;
      &lt;p&gt;
        &lt;a href="http://validator.w3.org/check?uri=referer"&gt;&lt;img
          src="http://www.w3.org/Icons/valid-xhtml11"
          alt="Valid XHTML 1.1" height="31" width="88" /&gt;&lt;/a&gt;
      &lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>