← Back to challenges

Simple OOP Calculator

JavaScriptHardclassesmathnumbers

Instructions

Create functions for the Calculator class that can do the following:

  • Add two numbers.
  • Subtract two numbers.
  • Multiply two numbers.
  • Divide two numbers.

Examples

var calculator = new Calculator()

calculator.add(10, 5) ➞ 15

calculator.subtract(10, 5) ➞ 5

calculator.multiply(10, 5) ➞ 50

calculator.divide(10, 5) ➞ 2

Notes

The functions should return the result of the calculation.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Coding Website Score Calculator