I want to have my calculator to display "0" when cleared or no other numbers have been entered but when I start adding numbers I want the 0 to be replaced. Currently when I enter any number it replaces the number on the display to the number entered.
this.currentDisplay = "0"
numberData(number) {
if (number === "." && this.currentDisplay.includes("."))
return
if (this.currentDisplay = "0") {
this.currentDisplay = this.currentDisplay.toString().replace("0", number.toString())
}
else {
this.currentDisplay = this.currentDisplay.toString() + number.toString()
}
}
>Solution :
You have an error on the this condition:
if (this.currentDisplay == "0") {
...
}
In your code you are assigning this.currentDisplay = 0, you should compare with == or better === to compare the types of the variables too.