/js-calculator

[js] Practice JS objects and functions.

Primary LanguageJavaScript

Javascript Calculator

Your task is to create a Javascript object that represents a calculator. It should have methods that provide it with the following functionality...

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Exponents (Hint: Look up Javascript's Math object)
  • An operation of your choice!

You should be able to run these methods like so from your browser's Javascript console...

calculator.add(1,2);
// => 3

Bonus 1

Give your calculator memory and allow it to persist the result of multiple operations.

  • Store this result in a value property.
  • Give your calculator a clear method that resets value.

For example:

calculator.add(1)
// value is 1
calculator.add(2)
// value is 3
calculator.add(2)
// value is 5
calculator.multiply(2)
// value is 10

Bonus 2

Give your calculator a "master" method that can parse through a string of operations (e.g., (2 - 1) * (5 ^ 2))

  • Your calculator should still have memory.