• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

149
Vistas
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)
almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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
almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda