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

240
Views
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 answers
Answer question

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 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!