title: Calculator: string together several operations and get the right answer, with each pair of numbers being evaluated at a time
body: <p>I'm working on a calculator project and I'm stuck at the point where I would like to string together several operations. Right now the calculator works but its functionality stops at one operation.</p>
  <p>My idea is to store the result of the first operation as the num1 of a following operation, in case the user decides to proceed.</p>
  <p>This is what the main function looks like right now:</p>
  <pre><code>let displayInput = &quot;&quot;;
  let num1 = &quot;&quot;;
  let num2 = &quot;&quot;;
  let operator = &quot;&quot;;
  
  buttons.forEach((button) =&gt; {
    button.addEventListener(&quot;click&quot;, firstOperation);
  });
  
  function firstOperation(e) {
    if (e.target.classList.contains(&quot;clear&quot;)) {
      clearIt();
    } else if (e.target.classList.contains(&quot;digit&quot;)) {
      display.textContent += e.target.innerText;
      displayInput = +display.textContent;
    } else if (e.target.classList.contains(&quot;operator&quot;)) {
      num1 = displayInput;
      operator = e.target.innerText;
      display.textContent = &quot;&quot;;
    } else if (e.target.classList.contains(&quot;equal&quot;)) {
      if (num1 == &quot;&quot; &amp;&amp; num2 == &quot;&quot; &amp;&amp; operator == &quot;&quot;) {
        return;
      } else {
        num2 = displayInput;
        display.textContent = &quot;&quot;;
        operate(operator, num1, num2);
        let firstOp = +display.textContent;
      }
    }
  }
  </code></pre>
  <p>I don't want a solution but if someone could point me in the right direction, that would be appreciated. Thanks.</p>