I’ve added an AC button to my JS calculator which resets the variables and displays 0 in the displayArea.
However when the user starts typing their first number the 0 stay’s so it shows 03 instead of 3 etc – this doesn’t impact the calculation.
I’ve tried to remove this using parseInt and an IF statement however it doesn’t seem to work.
My best attempt so far is:
<p id="result-display"> </p>
let displayArea = document.getElementById('result-display');
else if (displayArea.innerHTML = 0) {
buttonNumber = Number(e.target.innerText);
displayValue = buttonNumber;
displayArea.innerHTML = parseInt(displayArea.innerHTML += displayValue);
}
If I change the 0 to a string e.g. ‘0’ it works but then also stops the user entering multiple number values e.g. 56 would show as 5 etc.
My JSFiddle is: https://jsfiddle.net/mh85skxv/3/