Solution Review: Calculator

Solution to the exercise 'Calculator'.

We'll cover the following

Solution

The solution depends on first listing all the possible values the operator can take:

  • '+'
  • '-'
  • '/'
  • '*'

Then, use operator === '<some operator>' to see if it is equal to any of the operators above. Create if conditions to cater to each condition for the respective operation. Finally, assign it to ans.

Variant 1

The code below shows simple if and else if conditions solve this problem.

Get hands-on with 1200+ tech skills courses.