title: How to show calculation history in javascript when making a html-based calculator
body: <p>I was trying to make an HTML-based calculator and it also displays the previous calculation history but I was confused about how to do it.<br>
  How to store the previous calculation results as a string a something else that can be used later on?
  Hi, I was trying to make an HTML-based calculator and it also displays the previous calculation history but I was confused about how to do it.<br>
  How to store the previous calculation results as a string a something else that can be used later on?</p>
  
  <pre><code>&lt;html&gt; 
     &lt;head&gt; 
        &lt;script&gt; 
           //function that display value 
           function dis(val) 
           { 
               document.getElementById("result").value+=val 
           } 
  
           //function that evaluates the digit and return result 
           function solve() 
           { 
               let x = document.getElementById("result").value 
               let y = eval(x) 
               document.getElementById("result").value = y 
           } 
  
           //function that clear the display 
           function clr() 
           { 
               document.getElementById("result").value = "" 
           } 
        &lt;/script&gt; 
        &lt;!-- for styling --&gt;
        &lt;style&gt; 
           .title{ 
           margin-bottom: 10px; 
           text-align:center; 
           width: 175px; 
           color:grey; 
           border: solid black 2px; 
           } 
  
           input[type="button"] 
           { 
           background-color:grey; 
           color: black; 
           border: solid black 2px; 
           width:100% 
           } 
  
           input[type="text"] 
           { 
           background-color:white; 
           border: solid black 2px; 
           width:100% 
           } 
        &lt;/style&gt; 
     &lt;/head&gt; 
     &lt;!-- create table --&gt;
     &lt;body&gt; 
        &lt;div class = title &gt;ITP2 Calculator&lt;/div&gt; 
        &lt;table border="1"&gt; 
           &lt;tr&gt; 
              &lt;td colspan="3"&gt;&lt;input type="text" id="result"/&gt;&lt;/td&gt; 
              &lt;!-- clr() function will call clr to clear all value --&gt;
           &lt;/tr&gt; 
           &lt;tr&gt; 
              &lt;!-- create button and assign value to each button --&gt;
              &lt;!-- dis("1") will call function dis to display value --&gt;
              &lt;td&gt;&lt;input type="button" value="1" onclick="dis('1')"/&gt; &lt;/td&gt; 
              &lt;td&gt;&lt;input type="button" value="3" onclick="dis('3')"/&gt; &lt;/td&gt; 
              &lt;td&gt;&lt;input type="button" value="+" onclick="dis('+')"/&gt; &lt;/td&gt; 
           &lt;/tr&gt; 
           &lt;tr&gt; 
              &lt;td&gt;&lt;input type="button" value="5" onclick="dis('5')"/&gt; &lt;/td&gt;  
              &lt;td&gt;&lt;input type="button" value="7" onclick="dis('7')"/&gt; &lt;/td&gt; 
              &lt;td&gt;&lt;input type="button" value="/" onclick="dis('')"/&gt; &lt;/td&gt; 
           &lt;/tr&gt; 
           &lt;tr&gt; 
              &lt;td&gt;&lt;input type="button" value="9" onclick="dis('9')"/&gt; &lt;/td&gt; 
              &lt;td&gt;&lt;input type="button" value="Clr" onclick="clr()"/&gt; &lt;/td&gt;
              &lt;td&gt;&lt;input type="button" value="=" onclick="solve()"/&gt; &lt;/td&gt;   
           &lt;/tr&gt; 
        &lt;/table&gt; 
     &lt;/body&gt; 
  &lt;/html&gt;  
  </code></pre>
  
  <p>Display history examples:
  2+3=5
  3+5=8</p>