Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript (2015) Introduction to Methods Finishing the Calculator

Hamed Ali
Hamed Ali
5,626 Points

Does anyone know what I am doing wrong with this subtract method here?

Does anyone know what I am doing wrong with this subtract method here?

calculator.js
var calculator = {
  sum: 0,
  add: function(value) {
    this.sum += value;
  },

  sum: 0,
  subtract: function(value) {
      this.subtract -= value;
  },

  multiply: function(value) {

  },
  divide: function(value) {

  },
  clear: function() {     // clears the screen
    this.sum = 0;
  }, 
  equals: function() {    //returns the sum
    return this.sum;
  }
}

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Hamed.

You do not have to use subtract but still have to use sum, so:

this.sum -= value

Hope this helps