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

242
Visualizações
Comparing math operator with string

I'm starting at web development and trying to create my first web app, a calculator, but I bumped into a bit of a problem.

I wanted an app where the user wrote the operator of the operation that needs to be performed and then the program would check this operator and run the specified equation. I know how to perform this in Python but I cannot use the same approach in JS in an HTML file.

In Python I would do something like this:

a = 4
b = 4
operator = '+'

if operator == '+':
    print(a+b)
if operator == '-':
    print(a-b)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So I've got it to work. I was not getting the value as I was trying to compare it.

so I was trying with

if (operator == '+'):
   equation = value_b + value_a

And it should be

if (operator.value == '+'):
   equation = value_b + value_a
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