title: Have JS auto complete math equations for a calculator app
body: <p>The issue I am having is that the math is not working as intended. I would like the calculator to auto evaluate the amount if the length of the <code>fullAmount</code> variable length is equal to 3 and then clear the <code>num</code> variable and the <code>fullAmount</code> variable but leave the current number that has been evaluated. So if you put <code>9 * 1</code> into the calculator I want it to leave <code>num = []</code> and <code>fullAmount = [9]</code> but it is currently leaving the <code>fullAmount</code> with <code>[9,*,1]</code> and then adds on to it. </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>$(document).ready(function() {
  
    var fullAmount = []
  
    var num = []
  
    var func = null
  
    function evaluate(array) {
      if (array[1] === "+") {
        var complete = array[0] + array[2]
        array = [complete]
        fullAmount.push(func[0])
        console.log(complete)
      } else if (array[1] === "-") {
        var complete = array[0] - array[2]
        array = [complete]
        fullAmount.push(func[0])
        console.log(complete)
      } else if (array[1] === "X") {
        var complete = array[0] * array[2]
        array = [complete]
        fullAmount.push(func[0])
        console.log(complete)
      } else if (array[1] === "÷") {
        var complete = array[0] / array[2]
        array = [complete]
        fullAmount.push(func[0])
        console.log(complete)
      } else {
        console.log("error")
      }
      $("#res").val(complete);
    }
  
    $('.num').click(function() {
      num.push($(this).text())
      console.log(num)
      console.log(fullAmount)
      $("#res").val(num.join(''));
    });
  
    $('.action').click(function() {
      func = $(this).text();
      num = num.join("")
      fullAmount.push(parseInt(num))
      if (fullAmount.length &gt;= 3) {
        evaluate(fullAmount)
      } else {
        fullAmount.push(func[0])
        console.log(func)
      }
  
      $("#res").val(fullAmount);
      func = null
      num = []
    });
  
  
  
    $('#equals').click(function() {
      if (fullAmount[1] === "+") {
        fullAmount.push(parseInt(num))
        var complete = fullAmount[0] + fullAmount[2]
        fullAmount = [complete]
        console.log(complete)
      } else if (fullAmount[1] === "-") {
        fullAmount.push(parseInt(num))
        var complete = fullAmount[0] - fullAmount[2]
        fullAmount = [complete]
        console.log(complete)
      } else if (fullAmount[1] === "X") {
        fullAmount.push(parseInt(num))
        var complete = fullAmount[0] * fullAmount[2]
        fullAmount = [complete]
        console.log(complete)
      } else if (fullAmount[1] === "÷") {
        fullAmount.push(parseInt(num))
        var complete = fullAmount[0] / fullAmount[2]
        fullAmount = [complete]
        console.log(complete)
      } else {
        console.log("error")
      }
      $("#res").val(complete);
    });
  
    $('#clear').click(function() {
      num = []
      fullAmount = []
      func = null
      $("#res").val("")
      console.log(num)
      console.log(fullAmount)
      console.log(func)
  
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"&gt;
    &lt;/script&gt;
    &lt;script src="calc.js"&gt;&lt;/script&gt;
    &lt;link rel="stylesheet" type="text/css" href="calc.css"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;div id="calculator-container"&gt;
      &lt;form class="show"&gt;
        &lt;input type="text" id="res" name="numbers" disabled&gt;&lt;br&gt;
      &lt;/form&gt;
      &lt;center&gt;
        &lt;div class="calculator-view"&gt;
          &lt;table&gt;
            &lt;tr&gt;
              &lt;td&gt;
                &lt;button id="clear" type="button"&gt;AC&lt;/button&gt;
                &lt;button id="sign" class="action" type="button"&gt;+/-&lt;/button&gt;
                &lt;button id="divide" class="action" type="button"&gt;÷&lt;/button&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;
                &lt;button id="seven" class="num" type="button"&gt;7&lt;/button&gt;
                &lt;button id="eight" class="num" type="button"&gt;8&lt;/button&gt;
                &lt;button id="nine" class="num" type="button"&gt;9&lt;/button&gt;
                &lt;button id="multiply" class="action" type="button"&gt;X&lt;/button&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;
                &lt;button id="four" class="num" type="button"&gt;4&lt;/button&gt;
                &lt;button id="five" class="num" type="button"&gt;5&lt;/button&gt;
                &lt;button id="six" class="num" class="num" type="button"&gt;6&lt;/button&gt;
                &lt;button id="minus" class="action" type="button"&gt;-&lt;/button&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;
                &lt;button id="one" class="num" type="button"&gt;1&lt;/button&gt;
                &lt;button id="two" class="num" type="button"&gt;2&lt;/button&gt;
                &lt;button id="three" class="num" type="button"&gt;3&lt;/button&gt;
                &lt;button id="plus" class="action" type="button"&gt;+&lt;/button&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;
                &lt;button id="zero" class="num" type="button"&gt;0&lt;/button&gt;
                &lt;button id="equals" type="button"&gt;=&lt;/button&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
          &lt;/table&gt;
        &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>