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

75
Views
Checking a Calculator display has one number in the innerHTML string

I'm working on a calculator with vanilla JavaScript. I'm trying to make an if statement to find out whether the current result displayed has only one number left in the string. If this is true I want to make sure when the user clicks the delete button the current display returns to the default display instead of having no numbers in the string. I hope I explained this properly. How would I go about making this check.

const deleteNumber = () => {
    let newDisplayedResult = currentResult[0].innerHTML.slice(0, -1);

    if (firstNumber !== "" && currentOperator !== "") {
        secondNumber = newDisplayedResult;
        currentResult[0].innerHTML = newDisplayedResult;
    } else {
        firstNumber = newDisplayedResult;
        currentResult[0].innerHTML = newDisplayedResult;
    }
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

let re = new RegExp('^[0-9]$');
re.test(str)

or:

str.length === 1 && "0123456789".split("").includes(str) 
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!