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 trialBrittany Smith
8,046 Pointsimplement the subtract function: am I overthinking this?
I can't help but assume I'm over thinking this. I tried just changing the + at the top to a - and it told me to stop cheating? The videos before this have been about using this. but I must be missing a step?
var calculator = {
sum: 0,
add: function(value) {
this.sum += value;
},
subtract: function(value) {
this.subtract
},
multiply: function(value) {
this.multiply
},
divide: function(value) {
this.divide
},
clear: function() {
this.sum = 0;
},
equals: function() {
return this.sum;
}
}
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Brittany,
You may be 'misthinking' the challenge. You shouldn't be changing the + because that is part of the add
method and needs to be a + sign. Task 1 wants you to add the code to make the subtract
method work, Task 2 the multiply
... and so forth.
var calculator = {
sum: 0,
add: function(value) {
this.sum += value;
},
subtract: function(value) {
// Task one code goes here
},
multiply: function(value) {
// Task two code goes here
},
divide: function(value) {
// Task three code goes here
},
clear: function() {
this.sum = 0;
},
equals: function() {
return this.sum;
}
}
The code would be the same as the add method, but with the respective math symbols for the associated methods.
Hope that helps :)
Keep Coding!
Valeriia O
Courses Plus Student 17,625 PointsValeriia O
Courses Plus Student 17,625 PointsThat was a great explanation, thanks so much!