Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

86
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda