'Updating display on JS calculator
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()
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
