I made a basic calculator. I’m trying to mimic google’s calculator when deleting an operator, it deletes the empty strings around the operator as well. This is the delete button I have.
deletebtn.addEventListener('click', () => {
currentDisplay.textContent = currentDisplay.textContent.slice(0, -1);
})
I’ve tried ‘if’ statements with split(), replace(), substring() to no avail.
2
Answers
You should beware of the display element you use. If
currentDisplay
is<input>
element then you can usecurrentDisplay.value
to get and set the value.If
currentDisplay
is not<input>
element then you can usecurrentDisplay.textContent
to get and set the value.CE stands for Clear Entry. In your case, based on your code, I think this should suffice: