I am trying to copy the number of user input in the "prev" div when the user clicks on an operation sign. Any idea how I can improve my code? When I click an operation button my text disappears and I get the error in the same place.
function calculate(button) {
let number = (button.innerHTML)
let current = document.getElementById("current")
let currentTotal = (current.innerHTML)
let newTotal = currentTotal + number
current.innerHTML = newTotal
}
function operation(){
let current = document.getElementById("current")
let prev = document.getElementById("prev")
current.innerHTML = prev
}
<div class="calc-grid">
<div id="result">
<div id="prev"></div>
<div id="current"></div>
</div>
<button class='span' onclick="AC()">AC</button>
<button>DEL</button>
<button onClick="operation()">÷</button>
<button onClick="calculate(this)">1</button>
<button onClick="calculate(this)">2</button>
<button onClick="calculate(this)">3</button>
<button onClick="operation()">*</button>
<button onClick="calculate(this)">4</button>
<button onClick="calculate(this)">5</button>
<button onClick="calculate(this)">6</button>
<button onClick="operation()">+</button>
<button onClick="calculate(this)">7</button>
<button onClick="calculate(this)">8</button>
<button onClick="calculate(this)">9</button>
<button onClick="operation()">-</button>
<button onClick="calculate(this)">.</button>
<button onClick="calculate(this)">0</button>
<button class='span'>=</button>
</div>