+ 2

How can I make a backspace button for my calculator?

I'm making a simple calculator. I've made almost everything of the calculator. But I can't make a backspace button for my calculator. :( If anyone know any easy way then please tell... :) I made my reset button like this: function reset() { document.getElementById('display').value=""; } But I have no idea to make a backspace button.

2nd Jun 2018, 1:48 PM
Rejwan Islam
Rejwan Islam - avatar
2 Antworten
+ 7
function backspace(){ var len=document.getElementById('display'); var inner=len.innerHTML; len=""; inner=inner.split(""); inner=inner.splice(inner.length-1,1) inner=inner.join(""); len.value=inner; }
2nd Jun 2018, 2:01 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 2
since the value of your calculator is being stored as a string remove the last value in the string
2nd Jun 2018, 1:57 PM
᠌᠌Code X
᠌᠌Code X - avatar