Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

63
Views
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()
        }
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!