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

85
Views
Javascript calculator how to allow multiple dots

So basically this project is almost done. But when I was 'testing' it, I found out, that I can't create multiple dots. I know why I can't do that :

// if there is any dot, and user want to add another dot, then return
    if(containDot && operand == '.') return;

So, the problem is that I have no other idea, how can I block adding multiple dots on ONE number and at the same time allow adding it into another numbers with idea for making operations with eval();

Here's link to code: https://codepen.io/Igor34/pen/LYyoZMR

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I modified your code to split the text into each number and look for a dot only on the last number.

const currentOperator = this.currentScreen.textContent.split(/[-+\\/\\*]/).pop();
// if there is any dot, and user want to add another dot, then return
if (currentOperator.includes(".") && operand === ".") return

// LINE BELOW REMOVED
// if(containDot && operand == '.') return;

See https://codepen.io/jmendes/pen/XWRwjJm

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!