How can I make a backspace button for my calculator? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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 ответов
+ 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
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - 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
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar